Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close the stream when receiving "done" event from the server #219

Merged
merged 2 commits into from
Mar 12, 2024

Conversation

aron
Copy link
Contributor

@aron aron commented Mar 12, 2024

This fixes a regression introduced with #214 where we were not exiting correctly when getting the "done" event from the server. This was picked up by the introduction of the CloudFlare integration tests added in #217 which uses the streaming API.

Once the fix was added it turns out that the nock() tests were incorrectly passing due to some internal weirdness when using respondWith and a Readable object. I wasn't able to get this working without hitting a different error:

TypeError: Invalid state: Controller is already closed

It looks like nock is retaining some global state somewhere in it's implementation and streams are being retained across requests. No combination of resetting mocks seemed to fix it.

In the end I just mocked out the fetch function passed into the createReadableStream library and returned a Response. I think we should probably do this everywhere rather than use nock() as the Request/Response APIs provided by fetch are much better now than the old node http lib.

aron added 2 commits March 12, 2024 10:25
Otherwise we hold the connection open indefinitely.

This surfaced an issue in the `nock` patching of the ReadableStreams when using `fetch()` so instead we end up mocking fetch directly and providing the stream as a response.
@aron aron changed the title Increase timeout in the cloudflare-worker Close the stream when receiving "done" event from the server Mar 12, 2024
@aron aron merged commit 82d9056 into main Mar 12, 2024
12 checks passed
@aron aron deleted the increase-test-duration branch March 12, 2024 13:36
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.

None yet

2 participants