Skip to content

fix: avoid derp-related panic during wsproxy registration#22322

Merged
deansheather merged 1 commit intomainfrom
dean/wsproxy-derp-mesh-key-fix
Feb 26, 2026
Merged

fix: avoid derp-related panic during wsproxy registration#22322
deansheather merged 1 commit intomainfrom
dean/wsproxy-derp-mesh-key-fix

Conversation

@deansheather
Copy link
Member

If the primary had DERP disabled, workspace proxy registrations would fail with a panic, as the registration endpoint would attempt to access the mesh key from the nil DerpServer.

Changes the endpoint to query the database for the key.

Closes #22317

If the primary had DERP disabled, workspace proxy registrations would
fail with a panic, as the registration endpoint would attempt to access
the mesh key from the nil DerpServer.

Changes the endpoint to query the database for the key.
err := options.Database.InTx(func(tx database.Store) error {
// This will block until the lock is acquired, and will be
// automatically released when the transaction ends.
err := tx.AcquireLock(ctx, database.LockIDEnterpriseDeploymentSetup)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL we added this

Comment on lines +607 to +624
// Load the mesh key directly from the database. We don't retrieve the mesh
// key from the built-in DERP server because it may not be enabled.
//
// The mesh key is always generated at startup by an enterprise coderd
// server.
var meshKey string
if req.DerpEnabled {
var err error
meshKey, err = api.Database.GetDERPMeshKey(ctx)
if err != nil {
httpapi.InternalServerError(rw, xerrors.Errorf("get DERP mesh key: %w", err))
return
}
if meshKey == "" {
httpapi.InternalServerError(rw, xerrors.New("mesh key is empty"))
return
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@deansheather deansheather merged commit bef7eb9 into main Feb 26, 2026
29 checks passed
@deansheather deansheather deleted the dean/wsproxy-derp-mesh-key-fix branch February 26, 2026 13:07
@github-actions github-actions bot locked and limited conversation to collaborators Feb 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: starting a workspace proxy while built in DERP server disabled causes wsproxy to error and exit

2 participants