Repository navigation
Conversation
Quit from the tray took ~30s on Windows and flashed a console window: - The tray asked the core to stop with `taskkill /T` (no /F). That only sends WM_CLOSE, which the windowless core never receives, so the tray waited out its timeout and force-killed it, skipping the core's cleanup. The core now starts in its own process group and the tray sends it CTRL_BREAK, which Go delivers as SIGINT, so the normal graceful shutdown runs. - taskkill/tasklist were started without CREATE_NO_WINDOW, so each one flashed a console from the GUI tray. - Once the core got the signal, http.Server.Shutdown still waited the full 30s for the long-lived SSE (/events) and MCP streams, which never end on their own. Request contexts are now cancelled 2s after shutdown starts, so ordinary requests get a short grace and the streams return.
The Windows stop test slept 1s before sending CTRL_BREAK; a slow runner could deliver it before the child's handler was installed, killing the child outright. The helper now prints "ready" after signal.Notify and the test waits for it. Also drop the TestGracefulShutdownNoPanic stream change: every CI job skips that test, so it added no coverage.
…xy#1962) Squash of upstream PR smart-mcp-proxy#1962 (not yet merged upstream).
…xy#1962) Squash of upstream PR smart-mcp-proxy#1962 (not yet merged upstream).
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
4699042 to
52f0baa
Compare
…xy#1962) Squash of upstream PR smart-mcp-proxy#1962 (not yet merged upstream).
Stop() with no graceful signal possible uses grace 0, so time.After(0) and a closed doneCh were both ready and select picked at random: an already-exited child could be taskkill /T /F'd and reported as force killed. Check doneCh first, and again when the grace timer fires. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks @felipecrs, this is a careful diagnosis (WM_CLOSE never reaching a windowless console process, console flashes, SSE holding Checked: One thing to consider, one thing we pushed
Smoke test we'd appreciate on Windows (you already did most of this): start the tray with a stdio server using Docker isolation + an open |
Raise the post-Shutdown request-context grace from 2s to 5s so short tool calls can finish, name it requestShutdownGrace, and document that tool calls on the request context are cancelled after it on every OS. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… comment Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Pushed three small maintainer commits on top of your branch (your commits and authorship untouched):
Windows build, vet and test-compile are clean and the tray tests pass. CI for the new head needs approval first. |
…xy#1962) Squash of upstream PR smart-mcp-proxy#1962 (not yet merged upstream).
Problem
On Windows, clicking Quit in the tray flashed a console window and MCPProxy only exited ~30s later.
Three causes:
taskkill /PID <pid> /T(no/F), which only sendsWM_CLOSE. The core runs withCREATE_NO_WINDOW, so it has no window to receive it. The tray waited out its 30s timeout and then force-killed the core, skipping its cleanup.taskkill/tasklistwere started from the GUI (-H windowsgui) tray withoutCREATE_NO_WINDOW, so each one briefly opened a console.http.Server.Shutdownwaits for every active request. The SSE/eventsfeed and MCP streams held open by clients never end on their own, so it always sat out its 30s timeout (HTTP server forced shutdown due to timeout).Fix
CREATE_NEW_PROCESS_GROUP).Stop()attaches to the core's console and sendsCTRL_BREAK_EVENTto that group. Go delivers it as SIGINT, so the core runs its normal graceful shutdown. If the event can't be sent, the tray force-kills right away instead of waiting 45s.taskkill/tasklistgo through a smallmonitor.HiddenCommandhelper that setsCREATE_NO_WINDOW.BaseContextthat is cancelled 2s afterShutdownstarts (RegisterOnShutdown). Ordinary in-flight requests get a short grace period, and stream handlers see the cancellation and return.Testing
TestStopIsGracefulForWindowlessProcess(Windows):Stop()on a windowless child that exits only on SIGINT finishes in about 0.1s with exit code 0. The child reports when its signal handler is installed, so the test doesn't depend on timing. With the oldtaskkill /Tit fails after 46s with "force killed". Note that PR CI runs unit tests on Ubuntu only, so this test first runs in CI after merge (themainpush matrix includes Windows).TestGracefulShutdownNoPanicis the natural place for one, but every CI job skips it by name, so I left it alone. Checked manually on Windows with the real core and an open/eventsstream: stop time went from 30s to 2.4s.go test ./cmd/mcpproxy-tray/...andgo test ./internal/server/(CI skip regex) pass on Windows.go vetis clean for Windows and Linux. golangci-lint was not run locally.Not changed
signalProcessTree's graceful path, used only when the tray stops a core it did not start, still usestaskkill /T. SendingCTRL_BREAKto a process group the tray didn't create could reach other processes on that console, such as the user's terminal.