Skip to content

Honor context deadline in send operations to prevent indefinite hangs#227

Open
novahe wants to merge 1 commit intocontainerd:mainfrom
novahe:fix/issue-174-send-hang-context
Open

Honor context deadline in send operations to prevent indefinite hangs#227
novahe wants to merge 1 commit intocontainerd:mainfrom
novahe:fix/issue-174-send-hang-context

Conversation

@novahe
Copy link
Copy Markdown

@novahe novahe commented Mar 26, 2026

Description

fix #174
where ttrpc client send operations (Write/Flush) could hang indefinitely if the peer stopped reading, even when the request context had expired.

Changes

  1. Context-Aware Send Path: Updated Channel.send, Client.send, serverConn.run, and stream.send to accept and propagate context.Context.
  2. Write Deadlines & Cancellation:
    • Implemented net.Conn.SetWriteDeadline in channel.send based on the context's deadline.
    • Added a watcher goroutine in channel.send to support manual context cancellation (ctx.Done()), ensuring that context.WithCancel also interrupts blocked I/O.
  3. Robust Connection Management:
    • Introduced failSend to ensure that any write-side failure (including timeouts and cancellations) results in closing the underlying connection. This prevents protocol corruption due to partial bufio writes.
    • Added mapWriteTimeout to correctly translate I/O timeout errors into context.DeadlineExceeded or context.Canceled.
  4. Stream Cleanup: Updated createStreamWithContext to ensure that streams are properly removed from the client's internal map if the initial send fails.

@novahe novahe force-pushed the fix/issue-174-send-hang-context branch from 653b2cf to a881bb0 Compare March 26, 2026 16:33
@novahe novahe force-pushed the fix/issue-174-send-hang-context branch from a881bb0 to 786257d Compare March 26, 2026 16:43
@novahe
Copy link
Copy Markdown
Author

novahe commented Mar 26, 2026

PTAL @dmcgowan @ningmingxiao @samuelkarp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ttrpc client send hang, even ctx is timeout.

1 participant