Concurrent requests overwrite each other's instrumentation data
維護者通常 1 天內回覆
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 35/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 停滯
- 技術堆疊
- ruby
- 領域
- backend, observability
研究方向
Start with lib/mcp/instrumentation.rb, especially instrument_call and add_instrumentation_data, then read the concurrent shared server test in test/mcp/server_test.rb and the tool call instrumentation in lib/mcp/server.rb. Reproduce the interleaving described in the issue and check how request data reaches the callback; done when concurrent requests produce separate records with the correct tool names. An open pull request (#668) is already addressing this issue.
由索引模型根據 Issue 內容生成。
描述
Instrumentation#instrument_call keeps the per-request record in @instrumentation_data, an instance variable on the shared Server (instrumentation.rb:8). When two requests run at the same time on one server, for example Streamable HTTP on a threaded Rack server, the second request replaces the hash.
The first request then writes its later fields (client, error, duration) into the second request's hash and passes that hash to instrumentation_callback (instrumentation.rb:43, :48). The first request's own record, with its tool_name and tool_arguments (server.rb:1408), is never sent to the callback. around_request gets the original hash (instrumentation.rb:17) but misses the fields written after the swap.
Concurrent use of one server is supported (see test "#handle concurrent requests on a shared server report exceptions independently" in test/mcp/server_test.rb).
Repro
Run from the repository root with bundle exec ruby -I lib repro.rb:
require "mcp"
entered = Queue.new
release = Queue.new
slow_tool = MCP::Tool.define(name: "slow_tool") do
entered << true
release.pop
MCP::Tool::Response.new([{ type: "text", text: "slow" }])
end
fast_tool = MCP::Tool.define(name: "fast_tool") do
MCP::Tool::Response.new([{ type: "text", text: "fast" }])
end
records = Queue.new
configuration = MCP::Configuration.new
configuration.instrumentation_callback = ->(data) { records << data.dup }
server = MCP::Server.new(name: "example", tools: [slow_tool, fast_tool], configuration: configuration)
call = ->(id, name) { server.handle({ jsonrpc: "2.0", id: id, method: "tools/call", params: { name: name, arguments: {} } }) }
thread = Thread.new { call.call(1, "slow_tool") }
entered.pop
call.call(2, "fast_tool")
release << true
thread.join
p(2.times.map { records.pop[:tool_name] })
Expected: ["fast_tool", "slow_tool"]
Actual: ["fast_tool", "fast_tool"]
Suggested fix
Keep the record local to the request instead of on the shared server. For example, create the hash in instrument_call and pass it to add_instrumentation_data, or keep it in a fiber-local value that instrument_call sets and restores.
- 主要語言
- Ruby
- 星號
- 940
- 分支
- 143
- 平均合併
- 1 天 5 小時
- 30 天內合併 PR
- 48
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/ruby-sdk 的其他 Issue
-
Invalid UTF-8 in `MCP-Protocol-Version`, `Mcp-Method` or `Mcp-Name` gives 500 instead of 400可能已有人在做 @koic 於 1 天前認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 78/100
modelcontextprotocol/ruby-sdk#663 ·
維護者通常 1 天內回覆
-
`Client::Stdio` passes the whole parent environment to the server process可能已有人在做 @atesgoral 於 1 天前認領。 未關閉bug
難度 4/5 3-5 天 新手友好度 55/100
modelcontextprotocol/ruby-sdk#662 ·
維護者通常 1 天內回覆
-
Elicitation results are not checked against `requested_schema`, but the docs say they match it可能已有人在做 @atesgoral 於 1 天前認領。 未關閉bug
難度 3/5 1-2 天 新手友好度 35/100
modelcontextprotocol/ruby-sdk#661 ·
維護者通常 1 天內回覆
-
`JWTVerifier` answers 500 instead of 401 for a PS256 token when it verifies with an EC key (jwt < 3.3.0)可能已有人在做 @atesgoral 於 1 天前認領。 未關閉bug
難度 3/5 1-2 天 新手友好度 35/100
modelcontextprotocol/ruby-sdk#659 ·
維護者通常 1 天內回覆
-
`logging/setLevel` from one session changes the log level of other sessions可能已有人在做 @atesgoral 於 1 天前認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 35/100
modelcontextprotocol/ruby-sdk#658 ·
維護者通常 1 天內回覆
查看 modelcontextprotocol/ruby-sdk 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 76/100
rubys/roundhouse#1917 ·
-
test_rescues_connection_reset_on_issue_comments_lookup fails on master and blocks every pull request未關閉
難度 1/5 1 小時以內 新手友好度 91/100
zerocracy/judges-action#3142 ·
維護者通常 2 天內回覆
-
Malformed encoded_filters causes a 500, and keeps failing with session persistence可能已有人在做 @officialasishkumar 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 80/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100