Skip to content

Commit 56719cc

Browse files
author
bashar-515
authored
[RSDK-9869] Globally Manage Lifecycle of Shared Connection to App (#4761)
1 parent 7be8421 commit 56719cc

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

web/server/entrypoint.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,17 @@ func RunServer(ctx context.Context, args []string, _ logging.Logger) (err error)
192192

193193
// the underlying connection in `appConn` can be nil. In this case, a background Goroutine is kicked off to reattempt dials in a
194194
// serialized manner
195-
appConn, err := grpc.NewAppConn(ctx, cfgFromDisk.Cloud, logger.Sublogger("networking").Sublogger("app_connection"))
195+
appConnLogger := logger.Sublogger("networking").Sublogger("app_connection")
196+
appConn, err := grpc.NewAppConn(ctx, cfgFromDisk.Cloud, appConnLogger)
196197
if err != nil {
197198
return err
198199
}
200+
defer func() {
201+
err := appConn.Close()
202+
if err != nil {
203+
appConnLogger.Error(err)
204+
}
205+
}()
199206

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

474480
for {

web/server/restart_checker.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"time"
77

88
apppb "go.viam.com/api/app/v1"
9-
"go.viam.com/utils"
109
"go.viam.com/utils/rpc"
1110

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

2120
type needsRestartChecker interface {
2221
needsRestart(ctx context.Context) (bool, time.Duration, error)
23-
close()
2422
}
2523

2624
type needsRestartCheckerGRPC struct {
@@ -29,12 +27,6 @@ type needsRestartCheckerGRPC struct {
2927
client rpc.ClientConn
3028
}
3129

32-
func (c *needsRestartCheckerGRPC) close() {
33-
if c.client != nil {
34-
utils.UncheckedErrorFunc(c.client.Close)
35-
}
36-
}
37-
3830
// ForceRestart lets random other parts of the app request an exit.
3931
var ForceRestart bool
4032

0 commit comments

Comments
 (0)