Repository navigation
fix(logs): release the per-server log sink on every Disconnect - #1268
Merged
Merged
Conversation
The upstream server logger's lumberjack sink was wrapped in zapcore.AddSync and never closed, so a core held one open file handle per server it had ever logged for, for the life of the process. On Windows that also pins the file: since 2026-09-07 every internal/server test that spins up a Server failed in CI's t.TempDir() cleanup on server-<name>.log, turning the Unit Tests and E2E workflows red on every push to main (#1266). The file sink now doubles as an io.Closer, NewUpstreamServerLogger returns it, and core.Client closes it at the end of Disconnect — the one path RemoveServer, ShutdownAll and a reconnect all reach. lumberjack reopens the file on the next write, so a reconnecting server logs on unchanged. CreateUpstreamServerLogger keeps its shape for callers that cannot own the closer. Verified with lsof: after Server.Shutdown no fd points into the log dir; with closeUpstreamLog removed the server-*.log handle is still open. Closes #1266 Co-Authored-By: Claude Opus 5 <[email protected]>
… guard Cross-model review: the compatibility test wrote through the closer-less API (opening a file it could never close), and the Disconnect test swapped in a stub closer while the real sink stayed open. Both would have failed Windows CI's TempDir cleanup themselves. The former no longer writes; the latter's stub delegates to the real closer. Co-Authored-By: Claude Opus 5 <[email protected]>
Deploying mcpproxy-docs with
|
| Latest commit: |
26df234
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://fc4e3a3a.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-1266-close-upstream-log.mcpproxy-docs.pages.dev |
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 34691092434 --repo smart-mcp-proxy/mcpproxy-go
|
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.
Closes #1266
Problem
The per-server upstream logger's lumberjack sink was wrapped in
zapcore.AddSyncand never closed, so a core held one open file handle per server it had ever logged for, for the life of the process. On Windows an open handle also pins the file: since 2026-09-07 everyinternal/servertest that spins up aServerfailed CI'st.TempDir()cleanup onserver-<name>.log, turning theUnit TestsandE2E Testsworkflows red on every push tomain(they only run their Windows leg onmain, so PRs never saw it).Fix
internal/logs: the file sink is arotatingSink(lumberjack +Sync) that is also anio.Closer.NewUpstreamServerLoggerreturns the closer;CreateUpstreamServerLoggerkeeps its shape for callers that cannot own one.core.Clientstores the closer and closes it at the end ofDisconnectWithContext— the one pathRemoveServer,ShutdownAlland a reconnect all reach. lumberjack reopens the file on the nextWrite, so a reconnecting server logs on unchanged.Testing
TestNewUpstreamServerLogger_CloserReleasesTheFileAndWritesReopen: write → close → rename succeeds → write reopens (the rename is the real check on the Windows leg).TestDisconnect_ClosesTheUpstreamLogSink: Disconnect closes the sink, every time.lsoffrom aninternal/serverfixture: afterServer.Shutdown()no fd points into the log dir; withcloseUpstreamLogremoved theserver-*.loghandle is still open.go test -raceoninternal/logs internal/upstream/... internal/runtimeandinternal/server(CI skip regex) green;GOOS=windows go build ./...andgo vetclean; golangci-lint v2 0 issues.StopStderrMonitoring's 500 ms wait could log a late EOF and reopen the sink after Disconnect returns. That is pre-existing and does not affect the failing fixtures (their clients never connect); a terminal write fence forRemoveServer/ShutdownAllwould close it fully.🤖 Generated with Claude Code