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
Currently, when using
start(to start the system tenant) orstart-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
startandstart-sqlsafe (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
pgportinstead of assuming the default port, which is good practice anyway.[1]
cockroach/pkg/roachprod/roachprod.go
Lines 658 to 672 in b4bd6d7
[2]
cockroach/pkg/roachprod/install/cockroach.go
Lines 274 to 285 in d2cf1f8
Jira issue: CRDB-31742