Skip to content

roachprod: use a randomly available port by default in start and start-sql #111052

@renatolabs

Description

@renatolabs

Currently, when using start (to start the system tenant) or start-sql (to start an app tenant), the cockroach process binds to the default ports [1]. The only exception is for local clusters, where custom ports are not allowed [2].

We should move to a default of using a randomly available port when starting cockroach. This will eliminate assumptions in the code about the location of services, and also make start and start-sql safe (port-wise) automatically.

Currently, a lot of tests fail if we were to implement this policy change (see #111030). The fix for most (if not all) of the failures, however, is to use pgport instead of assuming the default port, which is good practice anyway.

[1]

func DefaultStartOpts() install.StartOpts {
return install.StartOpts{
Sequential: true,
EncryptedStores: false,
NumFilesLimit: config.DefaultNumFilesLimit,
SkipInit: false,
StoreCount: 1,
TenantID: 2,
ScheduleBackups: false,
ScheduleBackupArgs: "",
InitTarget: 1,
SQLPort: config.DefaultSQLPort,
AdminUIPort: config.DefaultAdminUIPort,
}
}

[2]

// Local clusters do not support specifying ports. An error is returned if we
// detect that they were set.
if c.IsLocal() && (startOpts.SQLPort != 0 || startOpts.AdminUIPort != 0) {
// We don't need to return an error if the ports are the default values
// specified in DefaultStartOps, as these have not been specified explicitly
// by the user.
if startOpts.SQLPort != config.DefaultSQLPort || startOpts.AdminUIPort != config.DefaultAdminUIPort {
return fmt.Errorf("local clusters do not support specifying ports")
}
startOpts.SQLPort = 0
startOpts.AdminUIPort = 0
}

Jira issue: CRDB-31742

Metadata

Metadata

Assignees

Labels

A-testingTesting tools and infrastructureC-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-testengTestEng Team

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions