Repository navigation
Close MCP auditor log file on server stop - #7373
Open
bharathvemula wants to merge 1 commit into
Open
bharathvemula wants to merge 1 commit into
bharathvemula wants to merge 1 commit into
Conversation
Server.Handler builds the MCP auditor with audit.NewAuditorWithTransport when AuditConfig is set, but only its middleware was kept, so Server.Stop never closed the log writer and each build/stop cycle leaked one file descriptor. Retain the auditor on the Server when Handler creates it and close it in Stop after the HTTP server has shut down, next to the session data storage close, following the WorkflowAuditor fix in stacklok#6110. Handler keeps the first auditor it creates; on repeat calls the surplus auditor is closed immediately so its log file is not leaked. The auditor creation call is left byte-identical to upstream so the WithSubjectEnricher argument added on main merges cleanly. Signed-off-by: Bharath Vemula <[email protected]>
bharathvemula
force-pushed
the
fix/7372-close-mcp-auditor-log-file
branch
from
November 28, 2026 23:59
73f9680 to
d376166
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7373 +/- ##
==========================================
+ Coverage 80.93% 82.64% +1.71%
==========================================
Files 867 934 +67
Lines 88888 97050 +8162
==========================================
+ Hits 71939 80207 +8268
+ Misses 16944 16838 -106
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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
Server.Handlerbuilds the MCP auditor withaudit.NewAuditorWithTransportwhenAuditConfigis set, but only its middleware was kept, soServer.Stopnever closed the auditor's log writer. Each server built with an audit log file leaked one file descriptor per build/stop cycle, which matters for embedders that build and stop vMCP servers repeatedly.ServerwhenHandlercreates it, and close it inStopafter the HTTP server has shut down, next to the session data storage close, so no in-flight request writes to a closed log file. A close error is reported with the other shutdown errors.WorkflowAuditorfix in Close workflow audit log writers #6110, including theos.Stdout/os.Stderrguard already inAuditor.Close, so a stdout-backed auditor is never closed.Fixes #7372
Type of change
Test plan
task test)task test-e2e)task lint-fix)Verified with the Taskfile's test flags on the touched package:
go test -ldflags=-extldflags=-Wl,-w -race -count=1 ./pkg/vmcp/server/— full package passes (254.967s at upstream HEAD; targeted audit tests re-run and passing after the rebase onto the fork'smain). New regression testTestStopClosesMCPAuditorLogFilebuilds a server with an audit log file, callsHandler, stops it, and asserts via/proc/self/fdthat no descriptor to the log file remains; it failed before theStopclose was added and passes with it.golangci-lint run ./pkg/vmcp/server/...: 0 issues;gofmtandgo vetclean.Special notes for reviewers
Handleris documented as safe to call multiple times; on a repeat call the retained auditor is reused instead of opening the log file again.Startfails afterHandlerhas built the auditor (listener creation or status reporter start), the auditor is released only when the caller callsStop; that path is unchanged by this fix and could be a follow-up if maintainers want it.main(Nov 10), which is behind upstreammain; the PR diff is the single fix commit only. The fork'smainpredates theAuditSubjectEnricheroption, so this version callsNewAuditorWithTransportwithout it — a rebase onto current upstreammainwould pick that option up with no other change.AI assistance disclosure: this PR was prepared with the help of an AI coding assistant; the author reviewed the changes and ran the tests above.