Skip to content

fix: don't call SwitchContext during in-cluster reconnect - #1400

Closed
syscod3 wants to merge 1 commit into
skyhook-io:mainfrom
syscode-labs:upstream-fix/in-cluster-reconnect-context-switch
Closed

fix: don't call SwitchContext during in-cluster reconnect#1400
syscod3 wants to merge 1 commit into
skyhook-io:mainfrom
syscode-labs:upstream-fix/in-cluster-reconnect-context-switch

Conversation

@syscod3

@syscod3 syscod3 commented Aug 9, 2026

Copy link
Copy Markdown

Summary

  • PerformContextSwitch always calls SwitchContext, which hard-rejects any call while running in-cluster (context switching is disabled there by design, per docs/configuration.md).
  • /connection/retry calls PerformContextSwitch(currentContext) to reconnect after a transient disconnect — in-cluster, that path could never succeed: it always failed on "cannot switch context when running in-cluster" and surfaced the generic connection-failed screen with a misleading raw error, instead of actually retrying.
  • In-cluster mode has one fixed context, so there's nothing to switch — skip SwitchContext and go straight to the connectivity test + subsystem reinit when IsInCluster().

Found live on an in-cluster Radar deployment: backend logs showed a repeating retry loop of Context switch FAILED at SwitchContext: cannot switch context when running in-cluster, while direct API calls (GET /api/contexts) kept returning 200 — the underlying k8s connectivity was fine, only the reconnect path was structurally broken.

Test plan

  • go build ./...
  • go test ./internal/k8s/...

Note

Medium Risk
Touches the shared context-switch/reconnect path after subsystem teardown; wrong branching could skip a needed kubeconfig switch or leave reconnect behavior inconsistent between modes.

Overview
PerformContextSwitch no longer calls SwitchContext when IsInCluster() is true. In-cluster Radar has a single fixed context, so reconnect (e.g. /connection/retry calling PerformContextSwitch with the current context) can proceed to the connectivity test and subsystem reinit instead of failing with cannot switch context when running in-cluster.

Out-of-cluster behavior is unchanged: SwitchContext still runs with the same error handling and timing logs.

Reviewed by Cursor Bugbot for commit 743d133. Bugbot is set up for automated code reviews on this repo. Configure here.

PerformContextSwitch always called SwitchContext, which hard-rejects
any call while running in-cluster (context switching is disabled
there by design, per docs/configuration.md). /connection/retry calls
PerformContextSwitch(currentContext) to reconnect after a transient
disconnect, so in-cluster reconnect could never succeed — it always
failed on "cannot switch context when running in-cluster" instead of
retrying, surfacing the generic connection-failed screen with a
misleading raw error.

In-cluster mode has one fixed context, so there's nothing to switch;
skip straight to the connectivity test + subsystem reinit.
@syscod3

syscod3 commented Aug 9, 2026

Copy link
Copy Markdown
Author

Folded into #1314 — this fix belongs with the postgres-timeline upstream contribution already in flight.

@syscod3 syscod3 closed this Aug 9, 2026
@syscod3
syscod3 deleted the upstream-fix/in-cluster-reconnect-context-switch branch August 9, 2026 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant