mcp-go
mcp-go copied to clipboard
Dustin/138 deadlock remove global mutex
This PR addresses #138. With the previous implementation the new tests will timeout due to the deadlock with the global mutex.
Summary by CodeRabbit
- Refactor
- Enhanced concurrency management by implementing multiple mutexes for different resource types, improving performance during simultaneous operations.
- Tests
- Added comprehensive tests to identify race conditions and deadlocks, ensuring reliable performance during concurrent usage.
Walkthrough
The pull request refactors the concurrency control in the MCPServer by replacing a single mutex with multiple dedicated sync.RWMutex fields for different resource types (resources, prompts, tools, middleware, notification handlers, and capabilities). Related methods now lock and unlock the appropriate mutex instead of the general one. Additionally, a new test file has been introduced to validate concurrent operations, specifically checking for race conditions and deadlocks through tests such as TestRaceConditions and TestConcurrentPromptAdd, along with a helper function to orchestrate concurrent operations.
Changes
| File | Change Summary |
|---|---|
| server/server.go | Replaced a single mutex with multiple dedicated mutexes (resourcesMu, promptsMu, toolsMu, middlewareMu, notificationHandlersMu, capabilitiesMu) in the MCPServer struct. Updated methods to lock/unlock the respective mutexes when accessing shared resources. |
| server/server_race_test.go | Introduced a new test suite to detect race conditions and deadlocks. Added test functions (TestRaceConditions, TestConcurrentPromptAdd) and a helper (runConcurrentOperation) to execute concurrent operations and validate the absence of concurrency issues. |
[!TIP]
⚡💬 Agentic Chat (Pro Plan, General Availability)
- We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
📜 Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 8d5b20c7ee1fc66fbd93d6590f1da44d607e5953 and 8815f14e997405247b7050e004611dee499117d5.
📒 Files selected for processing (1)
server/server_race_test.go(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- server/server_race_test.go
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai planto trigger planning for file edits and PR creation.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.