Skip to content

Commit

Permalink
track nextPort in Manager struct, port in module struct
Browse files Browse the repository at this point in the history
  • Loading branch information
abe-winter committed Dec 10, 2024
1 parent c3eb667 commit c83405a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions module/modmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -68,6 +71,7 @@ func NewManager(
restartCtx: restartCtx,
restartCtxCancel: restartCtxCancel,
packagesDir: options.PackagesDir,
nextPort: tcpPortRange,
}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c83405a

Please sign in to comment.