apollographql / apollographql/apollo-client-integrations
TeeToReadableStreamLink throws TypeError when stream closes before Observable completes
- Dominant language
- TypeScript
- Stars
- 556
- Forks
- 53
- PR merge metrics
- No merged PRs in 30d
Description
@apollo/client-react-streaming version: 0.14.4
[TeeToReadableStreamLink](https://github.com/apollographql/apollo-client-integrations/blob/43b0a18a265495220b2a2ed44ae654939e7d86a5/packages/client-react-streaming/src/ReadableStreamLink.tsx#L65) calls controller.enqueue() on a ReadableStreamDefaultController that has already been closed, throwing a type error:
> TypeError: Invalid state: Controller is already closed at ReadableStreamDefaultController.enqueue (node:internal/webstreams/readablestream:1077:13)
In TeeToReadableStreamLink, the cleanup function only sets subscribed = false, it doesn't cancel the inner forward(operation).subscribe(). If the ReadableStream consumer closes the stream (e.g. react SSR finishes rendering) while the inner subscription is still in flight then the subsequent controller.enqueue() calls throw
The controller.close() is already defensively wrapped in tryClose() but the three controller.enqueue() calls are not
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in packages/client-react-streaming/src/ReadableStreamLink.tsx at the linked TeeToReadableStreamLink implementation. Trace the cleanup function and the three controller.enqueue() calls while the inner forward(operation).subscribe() remains active; done means closing the stream before Observable completion no longer produces a controller-already-closed TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, web-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 76/100