-
-
Notifications
You must be signed in to change notification settings - Fork 109
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(polkompress): avoid hanging requests and/or runtime errors #648
Conversation
🦋 Changeset detectedLatest commit: 7345e89 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Size Change: +2 B (0%) Total Size: 759 kB
ℹ️ View Unchanged
|
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.
What a great catch! Can only imagine how long it took to debug this 👍
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.
🚀👽 to the moon
Wow, awesome debugging here. |
* Add @polka/compression package * skip brotli tests on unsupported node versions * allow Node>=6 * add stream piping test * kick CI * debug: drop action cache * debug: reattach cache step * fix: always call `writeHead` step - see preactjs/wmr#648 * chore: backport fixes; - now aligns w/ current wmr (and vite) impls * feat: add dual esm/cjs typescript definitions * chore: test types --------- Co-authored-by: Luke Edwards <luke.edwards05@gmail.com>
Ok, this one is a little long-winded:
The
polkompress
middleware didn't always "cleanup"/terminate the response correctly. Basically, our monkey-patchedres.writeHead
held a danglingpendingStatus
value for whenstart()
was done. However, this only worked if there was an explicit call tores.writeHead
somewhere in the application before thestart()
exits.I don't know if this just has to do with the fact that my test case used a small
body
(even when crossing the threshold) , but in my reproductions I saw that this was always the order:So, the
res.writeHead
call thatres.end
makes internally (native, not patched behavior) happens afterstart()
has already finished. This problem manifested as two different errors:When body was shorter than the threshold, it results in a hanging request that never terminates – at least until timeout takes over
When the body crosses the threshold (and does not take a while to finish compressing, I guess), this nasty error surfaces, which was seen in production (repro below):
You can get to both errors with this snippet & by playing with the
res.end
contents:I added tests (nearly crashed my computer, twice!!) for both variants of this error.