Client context is not honored while waiting for sendLock
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- go
- Domain
- backend-api-design
Research direction
Start by locating Client.createStream, Client.send, dispatch, and sendLock, then trace how cancellation is handled around channel.send and Flush. Done means a request waiting for the serializer returns promptly with context.Canceled or context.DeadlineExceeded; the issue names no file or test to run, so the surrounding client cancellation tests will need to be identified.
Written by the indexing model from the issue text.
Description
Description
This issue tracks a cancellation gap that remains in #227.
PR #227 makes the active socket write context-aware. That is necessary and fixes the case where the request currently blocked in Write or Flush has an expiring context.
However, it leaves acquisition of the client-wide send lock unchanged:
c.sendLock.Lock()
defer c.sendLock.Unlock()
Consequently, request B cannot observe its own context while request A owns sendLock. If A has a non-expiring or long-lived context and blocks while writing, B can remain inside sync.Mutex.Lock() indefinitely—even after B's deadline expires.
Execution path
Request A
-> createStream
-> sendLock.Lock()
-> channel.send
-> bufio.Writer.Flush() // blocked while holding sendLock
Request B
-> createStream
-> sendLock.Lock() // cannot observe B's ctx.Done()
dispatch does not reach its context-aware response wait until createStream returns.
The same problem exists in Client.send, affecting streaming SendMsg and CloseSend calls.
Expected behavior
A request canceled while waiting to submit its frame should return promptly with context.Canceled or context.DeadlineExceeded.
Its lifetime should not be determined by the context of the request currently holding the send serializer.
Actual behavior
If request A blocks while holding sendLock:
- Request B waits in
sendLock.Lock(). - B's context expires.
- B remains blocked.
- Further requests accumulate behind the same writer.
- The goroutines are released only when A returns or the connection is closed externally.
Impact
This can create connection-wide head-of-line blocking when a single ttrpc client is shared by unrelated operations.
In Kata-containers case:
- Metrics and lifecycle requests shared one long-lived ttrpc connection.
- If metrics send stopped making progress it's still holding the send lock.
- Later lifecycle requests can't be submitted.
- A process signal could not reach the guest, preventing normal container shutdown and cleanup.
- Dominant language
- Go
- Stars
- 674
- Forks
- 90
- Avg merge
- 16h 32m
- Merged PRs (30d)
- 2
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from containerd/ttrpc
-
Occasional streamHandler map memory leakMay be free again @fuweid claimed this 175 days ago, and no pull request is open. Open
containerd/ttrpc#236 · 1 reaction · 1 assignee ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
containerd/ttrpc#212 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
containerd/ttrpc#203 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
containerd/ttrpc#184 · 9 comments ·
-
ttrpc client send hang, even ctx is timeout.Possibly taken @novahe claimed this 251 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 45/100
containerd/ttrpc#174 · 7 comments ·
All issues in containerd/ttrpc
Similar issues
-
P3 tech debt
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Maintainers usually reply within 1 day
-
kind/feature needs-triage priority/unprioritized
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
NVIDIA/k8s-test-infra#1504 ·
Maintainers usually reply within 1 day
-
Area/Infrastructure Aspect/Infra Resources Type/Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
wso2/agent-manager#2717 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
open-policy-agent/opa#9685 · 1 comment ·
Maintainers usually reply within 1 day