fix(security): resolve race condition and resource leaks in flow tracker#299
Open
tjsingleton wants to merge 2 commits intosmart-mcp-proxy:027-data-flow-securityfrom
Open
fix(security): resolve race condition and resource leaks in flow tracker#299tjsingleton wants to merge 2 commits intosmart-mcp-proxy:027-data-flow-securityfrom
tjsingleton wants to merge 2 commits intosmart-mcp-proxy:027-data-flow-securityfrom
Conversation
…ker (Spec 027) - Change RLock→Lock in CheckFlow: method writes to session fields (LastActivity, ToolsUsed, Flows) which requires a write lock - Add flowService.Stop() in Runtime.Close() to halt background goroutines (sessionExpiryLoop, cleanupLoop) - Register SetExpiryCallback to emit activity flow summaries on session expiry, enabling the audit trail for data provenance
- TestFlowTracker_CheckFlow_ConcurrentRace: 15+ goroutines exercising concurrent CheckFlow+RecordOrigin to verify no data race - TestFlowService_Stop_Idempotent: triple-stop safety verification - TestFlowService_ExpiryCallback_EmitsSummary: verifies callback fires with correct FlowSummary on session expiry
8 tasks
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
Fixes 3 issues found during code review of #293 (Spec 027 data flow security):
CheckFlow()writes to session fields under read lock — changedRLocktoLockFlowService.Stop()never called inRuntime.Close()— added shutdown callSetExpiryCallbacknever registered — flow session summaries now emit to activity logChanges
Production fixes (
2611a32):internal/security/flow/tracker.go:RLock→LockinCheckFlow(writes toLastActivity,ToolsUsed,Flowsrequire write lock)internal/runtime/runtime.go: AddedflowService.Stop()inClose()before supervisor shutdowninternal/runtime/runtime.go: RegisteredSetExpiryCallbackafter Runtime construction to emitEventTypeActivityFlowSummaryRegression tests (
ab95259):TestFlowTracker_CheckFlow_ConcurrentRace: 15+ goroutines exercising concurrentCheckFlow+RecordOriginTestFlowService_Stop_Idempotent: triple-stop safetyTestFlowService_ExpiryCallback_EmitsSummary: verifies callback fires with correctFlowSummaryTest plan
go test -race ./internal/security/flow/...— all 34 tests passRLock)🤖 Generated with Claude Code