Skip to content

fix: finish the resumable stream when the source stream errors - #54

Open
RaphaelFakhri wants to merge 1 commit into
vercel:mainfrom
RaphaelFakhri:fix/producer-source-error
Open

RaphaelFakhri wants to merge 1 commit into
vercel:mainfrom
RaphaelFakhri:fix/producer-source-error

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Fixes #53.

When the stream from makeStream() errors, createNewResumableStream never handles the rejected reader.read(). This causes an unhandled promise rejection, and the sentinel stays at "1" for the 24 h TTL. Resumed streams never get DONE_MESSAGE, and every later resumeExistingStream call rejects with Timeout waiting for ack. The same thing happens if a Redis call in the read loop rejects.

Changes

  • Move the done cleanup into a finish function. It sets the sentinel to DONE, unsubscribes from the request channel, sends DONE_MESSAGE to listeners, and resolves the waitUntil promise.
  • Add a .catch to the read loop. On error, it cancels the source reader, errors the returned stream with the original error, and runs finish.
  • Add a shared test that errors the source mid-stream. It checks that the producer stream rejects with the source error, the resumed stream closes, hasExistingStream returns "DONE", and resumeExistingStream returns null.

Testing

REDIS_URL=redis://localhost:6379 npx vitest run

  • Before the fix: 5 failed, 90 passed, 5 unhandled rejections (Error: source failed).
  • After the fix: 95 passed.

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.

createNewResumableStream: an erroring source causes an unhandled rejection and leaves the stream resumable forever

1 participant