Repository navigation
fix(mcp): honor caller deadlines during gateway initialization - #939
Open
rudycelekli wants to merge 1 commit into
Open
rudycelekli wants to merge 1 commit into
rudycelekli wants to merge 1 commit into
Conversation
This was referenced Nov 16, 2026
Yanami-2K
approved these changes
Nov 16, 2026
Yanami-2K
left a comment
Collaborator
There was a problem hiding this comment.
核对了 internal/mcpclient/client.go:初始化不再用全程持有的 c.mu 串行,改成容量为 1 的 initGate 通道,排队时可以响应 ctx.Done();initialize 请求改用 NewRequestWithContext,调用方取消时返回 ctx.Err(),并且不把 c.init 置为 true,后续调用方可以重新初始化。测试断言了 DeadlineExceeded、重试成功,以及一共发出两次 initialize。非阻塞建议:“排队等 initGate 时超时”这条分支没有单独的测试;ensureInit 的 diff 后半段被截断,我没能确认通知那段里的 c.nextID++ 是否在 c.mu 保护下。它和 #935 改的是同一个结构体和 ensureInit,先合入哪个,另一个就需要 rebase。
1 task done
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.
What changed
CallToolContext and ListToolsContext applied cancellation only to the actual tool request. The initialize handshake could exceed the API caller deadline, including while a concurrent caller held the handshake lock. Bind both handshake requests to the caller context, allow cancellation while queued, and leave canceled initialization retryable.
Scope
Validation
A synthetic HTTP endpoint stalls the first initialization. Main exceeds the caller deadline, while the fixed client returns the deadline and a fresh caller successfully initializes. The mcpclient package tests and vet pass.
Full platform build and public browser checks were not run for this branch. All fixtures are synthetic.