fix: don't call SwitchContext during in-cluster reconnect - #1400
Closed
syscod3 wants to merge 1 commit into
Closed
Conversation
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.
Author
|
Folded into #1314 — this fix belongs with the postgres-timeline upstream contribution already in flight. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PerformContextSwitchalways callsSwitchContext, which hard-rejects any call while running in-cluster (context switching is disabled there by design, perdocs/configuration.md)./connection/retrycallsPerformContextSwitch(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.SwitchContextand go straight to the connectivity test + subsystem reinit whenIsInCluster().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
PerformContextSwitchno longer callsSwitchContextwhenIsInCluster()is true. In-cluster Radar has a single fixed context, so reconnect (e.g./connection/retrycallingPerformContextSwitchwith 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:
SwitchContextstill 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.