Skip to content

Fix streaming RPC cancel watcher lifetime#101

Closed
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/critical-bug-investigation-b888
Closed

Fix streaming RPC cancel watcher lifetime#101
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/critical-bug-investigation-b888

Conversation

@cursor

@cursor cursor Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

Streaming RPC handlers spawned detached cancel watcher coroutines that captured per-request AnyStreamWriter and RpcRequest stack objects by reference. After a stream completed normally, the watcher could remain blocked on the cancel channel and later dereference freed stack state or consume cancellation messages for a different in-flight stream, causing crashes, memory corruption, or lost stream cancellation.

Root cause

The cancel watcher lifetime was independent from the stream callback lifetime, while AnyStreamWriter also stored the request by reference.

Fix

  • Make stream writers own their RpcRequest metadata and use atomic cancellation state.
  • Allocate each active stream writer on the heap while its cancel watcher is alive.
  • Add a per-call interrupt pipe so each cancel watcher exits when the stream callback returns.
  • Apply the fix consistently across rpc, asio_rpc, coro_rpc, and co20_rpc server backends.

Validation

  • npx --yes @bazel/bazelisk test //asio_rpc/server:server_test //coro_rpc/server:server_test //co20_rpc/server:server_test //rpc/server:server_test
Open in Web View Automation 

cursoragent and others added 2 commits July 1, 2026 11:11
Co-authored-by: dallison <dallison@users.noreply.github.com>
Co-authored-by: dallison <dallison@users.noreply.github.com>
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.

2 participants