-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: only emit 'end' after unzip is done writing #1766
Conversation
8792b3c
to
d61eb63
Compare
d61eb63
to
ef969fa
Compare
is this ready for review? |
yes, I believe it is. |
Codecov ReportPatch coverage:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## master #1766 +/- ##
==========================================
+ Coverage 94.19% 94.45% +0.25%
==========================================
Files 14 14
Lines 1155 1155
==========================================
+ Hits 1088 1091 +3
+ Misses 67 64 -3
☔ View full report in Codecov by Sentry. |
If there's anything I can do to help with the review of this code, please let me know. |
Please let me know if there's anything I can do to help facilitate the review of this code. This bug can result in data loss for anyone using this library to pipe GZIP'ed content to a stream. The bug seems more prevalent when running node 18 or higher. |
v8.1.0 released which fixes this issue, thank you
release notes @ https://github.com/ladjs/superagent/releases/tag/v8.1.0 |
When using node:stream.pipeline or node:stream/promises.pipeline with superagent, the pipeline often fails with a 'write after end' error or with truncated data. This is because, in _pipeContinue, we are emitting 'end' as soon as the response is done. This is fine for normal requests, but for compressed content, there is an extra transform stream introduced in the pipe line. If we emit end on the agent request before the unzipObject transform stream is done writing data, pipeline will end the target stream too early and unzipObject will attempt to continue writing to the closed stream (resulting in an error, or, depending on the stream being written to, truncated data).
To fix, we make sure to emit 'end' on the agent request only after the unzipObject stream has finished writing.
Checklist