Repository navigation
fix(server): stop the status forwarder and routing listener on Shutdown - #1941
Conversation
NewServer starts two goroutines that Shutdown never stopped: forwardRuntimeStatus ranges over Runtime.StatusChannel(), which nothing closes, and listenForRoutingModeRefresh ranges over an event subscription Shutdown never unsubscribed. Each shut-down server kept both idle for the rest of the process (227 of each by the end of a full internal/server run). Keep the routing subscription on Server and unsubscribe it in Shutdown, which closes the channel and ends the listener (its deferred unsubscribe finds nothing left to do). Stop the forwarder with a server-owned done channel closed in Shutdown, leaving the runtime's status channel open so no sender can hit a closed channel. The shutdown flag keeps both one-shot.
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 44554678436 --repo smart-mcp-proxy/mcpproxy-go
|
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
TestE2E_TrayToCore_UnixSocket, TestE2E_DualListener_Concurrent and TestE2E_SocketPermissions never shut their server down, so each left its upstream manager's network-recovery watcher running. Since the TestMain leak guard (#1936) that fails the -run TestE2E job on main. Shut each server down in a defer that runs before the socketE2EMutex unlock.
Deploying mcpproxy-docs with
|
| Latest commit: |
d37adc7
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://23d395de.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-server-shutdown-stops-li.mcpproxy-docs.pages.dev |
… merge cleanly #1941 makes the same shutdown fix in socket_e2e_test.go. Taking its file byte-for-byte means whichever PR lands second merges without a conflict. The CI E2E command still passes with the leak guard.
… merge cleanly #1941 makes the same shutdown fix in socket_e2e_test.go. Taking its file byte-for-byte means whichever PR lands second merges without a conflict. The CI E2E command still passes with the leak guard.
|
Independent review (opencode github-copilot/gpt-6.1-sol, variant high) of the merge with main 9a59c08, tree 2dd86e793: VERDICT CLEAN. No double close of listenersDone (guarded by s.shutdown under s.mu). UnsubscribeEvents is safe against concurrent publishers (eventMu). TestShutdown_StopsServerListenerGoroutines passed 5x and 5x under -race. Residual: no test for concurrent Shutdown or busy listeners. |
Problem
NewServerstarts two goroutines thatServer.Shutdownnever stopped:forwardRuntimeStatusranges overRuntime.StatusChannel(). Nothing closes that channel.listenForRoutingModeRefreshranges over aSubscribeEvents()channel.Shutdownnever unsubscribed it.In a real process this does no harm because the process exits. But every server that is shut down inside a running process (tests, an in-process restart) leaves two idle goroutines behind for the rest of the process.
Fix (
internal/server/server.go)Servernow stores the routing subscription (routingEventsCh), andShutdownunsubscribes it.UnsubscribeEventscloses the channel, which ends the listener's range loop. The listener's own deferredUnsubscribeEventsthen finds no subscription left and does nothing.selects on a server-ownedlistenersDonechannel, whichShutdowncloses. The runtime'sstatusChstays open, so a status send can never hit a closed channel.s.shutdownguard, so a secondShutdownis still a no-op andlistenersDoneis closed only once.Tests
TestShutdown_StopsServerListenerGoroutines(internal/server/shutdown_listeners_test.go): builds a server withNewServer, callsShutdown, and polls (10s deadline) until neither frame is running above the count taken beforeNewServer. It then callsShutdowna second time. It failed before the fix (1/1of each still running after 10s) and passes after it (-race -count=5).go test -race -timeout 60m -skip "E2E|Binary|MCPProtocol|TestInfoEndpoint|TestGracefulShutdownNoPanic|TestSocketInfoEndpoint" ./internal/server/passes on both trees. Goroutines still running at the end of the run (counted by a local-onlyTestMainthat was not committed):forwardRuntimeStatuslistenForRoutingModeRefreshmain58a824e.github/.golangci.yml, bare and--build-tags server, with--new-from-rev=origin/main: 0 issues.Not in this PR
The
TestMainleak guard from #1936 (leak_guard_main_test.go) is not onmainyet. Once both PRs land, it can also check these two frames, since a full run now ends at zero.Also: E2E job red on
mainsince #1936The
-run TestE2Ejob has failed onmainsince #1936 (6251956, 201d373):FAIL: 3 upstream.Manager network-recovery watcher(s) still running. I traced the creators with pprof labels. All three are the socket E2E tests (TestE2E_TrayToCore_UnixSocket,TestE2E_DualListener_Concurrent,TestE2E_SocketPermissions), which deliberately never shut their server down. Each test now shuts its server down in adeferthat runs before thesocketE2EMutexunlock. The CI E2E command (go test -v -race -timeout 10m ./internal/server -run TestE2E -skip '…') now passes locally (255s), and the three tests pass with-race -count=3.