Repository navigation
fix(broker): take RLock in findServerByName and use MCPName() in log - #923
SarthakB11 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR adds RLock protection to ChangesSynchronization and Race Condition Prevention
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This will need a rebase against main. A few related PRs have merged that touch overlapping files:
The RLock fix and MCPName() logging fix in this PR should still apply, but please verify after rebasing. |
findServerByName iterates broker.mcpServers without taking broker.mcpLock, while OnConfigChange mutates the same map under the write lock. A tools/list call concurrent with a config reload can therefore data-race on the iteration. Mirror the locking pattern used by ToolAnnotations and GetServerInfo: take an RLock for the duration of the loop. Also fix the adjacent log line in filterToolsByServerMap which passed the method value upstream.MCPName instead of calling it. The slog encoder rendered a method-value formatter string instead of the actual server name, destroying the diagnostic value of the line. Add TestFilterTools_DataRace exercising FilterTools concurrently with a mutator that mirrors OnConfigChange under broker.mcpLock. Run with go test -race ./internal/broker/... Signed-off-by: SarthakB11 <[email protected]>
e446ebd to
03c1124
Compare
|
Rebased onto main. RLock fix and |
|
Hey, thanks for the contribution. Just a heads up: reviews are currently being prioritised around the v0.7 milestone. PRs tied to v0.7 issues will be reviewed first. We'll get to this one, but it may take a bit longer than usual. |
|
thanks @SarthakB11, closing -- this was already fixed on main by 904f2b7 (@Aman-Cool). |
Summary
Found another concurrency hole in the broker, in the same family as the recent
mcpServers/ session-cache fixes (#860, #872, #888, #918, #921).findServerByNameininternal/broker/filtered_tools_handler.goiteratesbroker.mcpServerswithout takingbroker.mcpLock.OnConfigChangemutates the same map under the write lock atbroker.go:175,190,197, so atools/listrequest that lands during a config reload races on the iteration. The existing helpersToolAnnotationsandGetServerInfoalready RLock around the same map, so this fix just bringsfindServerByNameinto line.While I was in the file I also fixed an adjacent log line in
filterToolsByServerMap. It passed the method valueupstream.MCPNameinstead of calling it (MCPName()), so slog rendered a method-value formatter string in place of the actual server name. Happy to split that into a separate PR if preferred.TestFilterTools_DataRaceexercisesFilterToolsand a mutator that mirrorsOnConfigChangeunderbroker.mcpLockfrom two goroutines. Pattern matchesmanager_test.go::TestMCPManager_status_DataRace. Run withgo test -race ./internal/broker/....Verification
Summary by CodeRabbit
Bug Fixes
Tests