Distinguish container restarts from exits in monitor#3937
Open
gkatz2 wants to merge 1 commit intostacklok:mainfrom
Open
Distinguish container restarts from exits in monitor#3937gkatz2 wants to merge 1 commit intostacklok:mainfrom
gkatz2 wants to merge 1 commit intostacklok:mainfrom
Conversation
The container monitor sends ErrContainerExited for both true exits and Docker restarts (detected via StartedAt change). The transport layer has no way to tell them apart, so it always tears down the proxy — killing a healthy container that Docker already restarted. Add ErrContainerRestarted sentinel error so the transport can handle restarts differently: reconnect the monitor to track the new start time while keeping the proxy running. Fixes stacklok#3936 Signed-off-by: Greg Katz <gkatz@indeed.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3937 +/- ##
==========================================
+ Coverage 67.62% 67.64% +0.01%
==========================================
Files 438 438
Lines 44108 44141 +33
==========================================
+ Hits 29829 29857 +28
- Misses 11945 11950 +5
Partials 2334 2334 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
ErrContainerRestartedsentinel error to distinguish Docker restarts from true container exitshandleContainerExitto reconnect the monitor and keep the proxy running when a restart is detectedshutdownChand add mutex protection inreconnectMonitorFixes #3936
Context
The container monitor detects Docker restarts by comparing
StartedAttimes (#3843), but reports them with the sameErrContainerExitederror as real exits. The transport layer can't tell them apart, so it always tears down the proxy and kills the already-running container. This causes cascading restart loops that take MCP servers offline — see #3936 for detailed impact.Changes
pkg/container/runtime/errors.go: NewErrContainerRestartedsentinelpkg/container/runtime/monitor.go: SendErrContainerRestartedwhen start time changespkg/container/docker/errors.go: Deprecated alias for backward compatibilitypkg/transport/http.go: Loop-basedhandleContainerExitthat reconnects the monitor on restart;reconnectMonitorwith mutex protection; double-close guard inStop()pkg/transport/http_test.go: Test case forShouldRestartwithErrContainerRestartedpkg/transport/stdio.go:ShouldRestartexcludesErrContainerRestartedTest plan
go test ./pkg/container/runtime/... ./pkg/transport/...)docker restart, confirmed proxy stayed up and MCP tool calls succeeded post-restartdocker stopstill correctly tears down the transport