Skip to content

Commit

Permalink
[RSDK-9869] Globally Manage Lifecycle of Shared Connection to App (vi…
Browse files Browse the repository at this point in the history
  • Loading branch information
bashar-515 authored Jan 30, 2025
1 parent 7be8421 commit 56719cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
10 changes: 8 additions & 2 deletions web/server/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,17 @@ func RunServer(ctx context.Context, args []string, _ logging.Logger) (err error)

// the underlying connection in `appConn` can be nil. In this case, a background Goroutine is kicked off to reattempt dials in a
// serialized manner
appConn, err := grpc.NewAppConn(ctx, cfgFromDisk.Cloud, logger.Sublogger("networking").Sublogger("app_connection"))
appConnLogger := logger.Sublogger("networking").Sublogger("app_connection")
appConn, err := grpc.NewAppConn(ctx, cfgFromDisk.Cloud, appConnLogger)
if err != nil {
return err
}
defer func() {
err := appConn.Close()
if err != nil {
appConnLogger.Error(err)
}
}()

// Start remote logging with config from disk.
// This is to ensure we make our best effort to write logs for failures loading the remote config.
Expand Down Expand Up @@ -468,7 +475,6 @@ func (s *robotServer) serveWeb(ctx context.Context, cfg *config.Config) (err err
utils.PanicCapturingGo(func() {
defer close(cloudRestartCheckerActive)
restartCheck := newRestartChecker(cfg.Cloud, s.logger, s.conn)
defer restartCheck.close()
restartInterval := defaultNeedsRestartCheckInterval

for {
Expand Down
8 changes: 0 additions & 8 deletions web/server/restart_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

apppb "go.viam.com/api/app/v1"
"go.viam.com/utils"
"go.viam.com/utils/rpc"

"go.viam.com/rdk/config"
Expand All @@ -20,7 +19,6 @@ const (

type needsRestartChecker interface {
needsRestart(ctx context.Context) (bool, time.Duration, error)
close()
}

type needsRestartCheckerGRPC struct {
Expand All @@ -29,12 +27,6 @@ type needsRestartCheckerGRPC struct {
client rpc.ClientConn
}

func (c *needsRestartCheckerGRPC) close() {
if c.client != nil {
utils.UncheckedErrorFunc(c.client.Close)
}
}

// ForceRestart lets random other parts of the app request an exit.
var ForceRestart bool

Expand Down

0 comments on commit 56719cc

Please sign in to comment.