From c83405a1ee204cd0fd7afe29eba5161309edca96 Mon Sep 17 00:00:00 2001 From: Abe Winter Date: Tue, 10 Dec 2024 15:37:19 -0500 Subject: [PATCH] track `nextPort` in Manager struct, `port` in module struct --- module/modmanager/manager.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/module/modmanager/manager.go b/module/modmanager/manager.go index 338b6035dcc..ebc7efcb60a 100644 --- a/module/modmanager/manager.go +++ b/module/modmanager/manager.go @@ -41,6 +41,9 @@ import ( rutils "go.viam.com/rdk/utils" ) +// tcpPortRange is the beginning of the port range. Only used when ViamTCPSockets() = true. +const tcpPortRange = 13500 + var ( validateConfigTimeout = 5 * time.Second errMessageExitStatus143 = "exit status 143" @@ -68,6 +71,7 @@ func NewManager( restartCtx: restartCtx, restartCtxCancel: restartCtxCancel, packagesDir: options.PackagesDir, + nextPort: tcpPortRange, } } @@ -100,6 +104,8 @@ type module struct { inStartup atomic.Bool inRecoveryLock sync.Mutex logger logging.Logger + // port stores the listen port of this module when ViamTCPSockets() = true. + port int } type addedResource struct { @@ -179,6 +185,8 @@ type Manager struct { removeOrphanedResources func(ctx context.Context, rNames []resource.Name) restartCtx context.Context restartCtxCancel context.CancelFunc + // nextPort manages ports when ViamTCPSockets() = true. + nextPort int } // Close terminates module connections and processes. @@ -317,7 +325,9 @@ func (mgr *Manager) add(ctx context.Context, conf config.Module) error { dataDir: moduleDataDir, resources: map[resource.Name]*addedResource{}, logger: mgr.logger.Sublogger(conf.Name), + port: mgr.nextPort, } + mgr.nextPort++ if err := mgr.startModule(ctx, mod); err != nil { return err @@ -1092,8 +1102,6 @@ func (mgr *Manager) FirstRun(ctx context.Context, conf config.Module) error { return conf.FirstRun(ctx, pkgsDir, dataDir, env, mgr.logger) } -var nextPort = 13500 - func (m *module) startProcess( ctx context.Context, parentAddr string,