-
-
Notifications
You must be signed in to change notification settings - Fork 37
fix(server): do not wait for response.write
for response.end
#2383
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
09901b5
fix(server): do not wait for `response.write` for `response.end`
ardatan b591d12
Changeset
ardatan 0700c63
Update packages/server/test/reproductions.spec.ts
ardatan 7d47ff7
Changeset
ardatan 31a6a9e
Fix
ardatan c7a6a98
Update whole-planes-mate.md
ardatan 3667f16
Update whole-planes-mate.md
ardatan 4c25bdc
Update whole-planes-mate.md
ardatan 874b0f2
Fix
ardatan c996c40
Handle formdata
ardatan f42fc8e
End stream gracefully
ardatan e8e31ba
Update changeset
ardatan 25d5aec
Try
ardatan 39a5cc4
Go
ardatan 9d0bd3e
Go
ardatan 1e764d6
Prettier
ardatan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
'@whatwg-node/node-fetch': patch | ||
'@whatwg-node/fetch': patch | ||
'@whatwg-node/server': patch | ||
--- | ||
|
||
Some implementations like `compression` npm package do not implement `response.write(data, callback)` signature, but whatwg-node/server waits for it to finish the response stream. | ||
Then it causes the response stream hangs when the compression package takes the stream over when the response data is larger than its threshold. | ||
|
||
It is actually a bug in `compression` package; | ||
[expressjs/compression#46](https://github.com/expressjs/compression/issues/46) | ||
But since it is a common mistake, we prefer to workaround this on our end. | ||
|
||
Now after calling `response.write`, it no longer uses callback but first it checks the result; | ||
|
||
if it is `true`, it means stream is drained and we can call `response.end` immediately. | ||
else if it is `false`, it means the stream is not drained yet, so we can wait for the `drain` event to call `response.end`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add type checking for stream values
After fixing the
currentAsyncIterator
type, we should ensure that the values being enqueued are of the expected type.📝 Committable suggestion
🤖 Prompt for AI Agents (early access)