quic: destroy stream on invalid promise body - #66260
christianaurichzm wants to merge 1 commit into
Conversation
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66260 +/- ##
==========================================
+ Coverage 90.30% 90.37% +0.06%
==========================================
Files 789 790 +1
Lines 272880 273847 +967
Branches 52106 52382 +276
==========================================
+ Hits 246423 247477 +1054
+ Misses 16918 16858 -60
+ Partials 9539 9512 -27
🚀 New features to boost your workflow:
|
pimterry
left a comment
There was a problem hiding this comment.
Thanks @christianaurichzm! Good find, fix LGTM.
Would be nice to avoid the extra Then step imo, but I don't feel strongly.
| body, | ||
| (resolved) => configureOutbound(handle, stream, resolved), | ||
| ), | ||
| undefined, |
There was a problem hiding this comment.
Nit: this adds another promise layer, which adds a microtask step and a small perf cost on every request, and we're only trying to catch sync errors so that layer's not really necessary.
Could we rewrite to use a try/catch inside the fulfilment step instead?
There was a problem hiding this comment.
Good point, done. I switched it to a try/catch in the fulfillment handler, so there’s no extra promise and rejected body values are handled the same way as before.
When `setBody()` receives a promise that resolves to an unsupported body type, `configureOutbound()` throws inside the fulfillment handler. The rejection handler only covered the original promise, so the error rejected a discarded promise and crashed the process as an unhandled rejection. Catch errors thrown by `configureOutbound()` in the fulfillment handler and destroy the stream with them, as the rejection handler already does. For an unsupported resolved value, `stream.closed` now rejects with the same `ERR_INVALID_ARG_TYPE` that `setBody()` throws synchronously. Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
3649ec9 to
413eb7d
Compare
stream.setBody(Promise.resolve(42))crashes the process with an unhandled rejection, whilestream.setBody(42)throwsERR_INVALID_ARG_TYPEsynchronously.configureOutbound()calls itself with the resolved value inside the fulfillment handler ofPromisePrototypeThen(). The rejection handler only coversbodyitself rejecting, so when that call throws, the error goes to the promise returned byPromisePrototypeThen(), which nothing handles.This wraps that call in a
try/catchand destroys the stream with the error, the same way the rejection handler already does. The same goes forERR_INVALID_STATEwhen the promise resolves to aFileHandlealready in use by another stream. Nothing changes for a body that rejects.On
mainthe new test crashes. With this change alltest/parallel/test-quic-*.mjstests pass andmake lintis clean.