Skip to content

Commit

Permalink
RSDK-9658: Use atomic counter for module port allocation. (#4684)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgottlieb authored Jan 7, 2025
1 parent 8eea820 commit 4df774c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions module/modmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewManager(
ctx context.Context, parentAddr string, logger logging.Logger, options modmanageroptions.Options,
) modmaninterface.ModuleManager {
restartCtx, restartCtxCancel := context.WithCancel(ctx)
return &Manager{
ret := &Manager{
logger: logger.Sublogger("modmanager"),
modules: moduleMap{},
parentAddr: parentAddr,
Expand All @@ -74,8 +74,9 @@ func NewManager(
restartCtxCancel: restartCtxCancel,
packagesDir: options.PackagesDir,
ftdc: options.FTDC,
nextPort: tcpPortRange,
}
ret.nextPort.Store(tcpPortRange)
return ret
}

type module struct {
Expand Down Expand Up @@ -191,7 +192,7 @@ type Manager struct {
restartCtxCancel context.CancelFunc
ftdc *ftdc.FTDC
// nextPort manages ports when ViamTCPSockets() = true.
nextPort int
nextPort atomic.Int32
}

// Close terminates module connections and processes.
Expand Down Expand Up @@ -333,9 +334,8 @@ func (mgr *Manager) add(ctx context.Context, conf config.Module, moduleLogger lo
resources: map[resource.Name]*addedResource{},
logger: moduleLogger,
ftdc: mgr.ftdc,
port: mgr.nextPort,
port: int(mgr.nextPort.Add(1)),
}
mgr.nextPort++

if err := mgr.startModule(ctx, mod); err != nil {
return err
Expand Down

0 comments on commit 4df774c

Please sign in to comment.