Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSDK-9658: Use atomic counter for module port allocation. #4684

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading