Skip to content

fix(client): make retryable stream buffering abort-aware - #5801

Open
Utkarshpandey0001 wants to merge 2 commits into
rivet-dev:mainfrom
Utkarshpandey0001:fix/client-fetch-stream-abort
Open

Utkarshpandey0001 wants to merge 2 commits into
rivet-dev:mainfrom
Utkarshpandey0001:fix/client-fetch-stream-abort

Conversation

@Utkarshpandey0001

Copy link
Copy Markdown

Hi Rivet team,

This PR fixes #5800, where ActorHandle.fetch() could remain pending indefinitely when a streaming request body was cancelled while being buffered for lifecycle retries.

Dynamic actor handles created through get() and getOrCreate() support retrying requests during actor lifecycle transitions. Because a ReadableStream can normally only be consumed once, RivetKit buffers the stream before attempting the request. That buffering previously ignored the request’s AbortSignal.

As a result, an already-aborted request—or a request aborted while buffering—would continue waiting for the stream to close. For long-running or open streams, the request would never settle and would never be dispatched to the actor.

What changed

  • Check the abort signal before reading a streaming request body.
  • Observe the signal throughout the buffering operation.
  • Cancel the active stream reader when the request is aborted.
  • Preserve and return the original abort reason to the caller.
  • Release the stream lock and remove the abort listener during cleanup.
  • Keep the existing retry behavior unchanged for successfully completed streams.

Test coverage

Regression tests were added for:

  • An already-aborted streaming request made through getOrCreate().
  • A request aborted while its stream is being buffered through get().
  • Preserving the original abort reason.
  • Cancelling and unlocking the source stream.
  • Ensuring no HTTP request is dispatched after cancellation.
  • Confirming existing streaming-body retry behavior continues to work.

Verification

  • Focused fetch-retry suite: 11 tests passed.
  • TypeScript type checking passed.
  • Biome formatting and lint checks passed.

Closes #5800

This branch has not been deployed

No deployments
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.

ActorHandle.fetch() ignores AbortSignal while buffering streaming request bodies

1 participant