Skip to content

Commit

Permalink
net: don't return the stream object from onStreamRead
Browse files Browse the repository at this point in the history
CallJSOnreadMethod expects the return value to be undefined or
a new buffer, so make sure to return nothing, even when an error
causes us to destroy the stream.

Fixes: #34346

PR-URL: #34375
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
robey authored and addaleax committed Sep 22, 2020
1 parent e9a8f0c commit 09056fd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/internal/stream_base_commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ function onStreamRead(arrayBuffer) {
}

if (nread !== UV_EOF) {
return stream.destroy(errnoException(nread, 'read'));
// #34375 CallJSOnreadMethod expects the return value to be a buffer.
stream.destroy(errnoException(nread, 'read'));
return;
}

// Defer this until we actually emit end
Expand All @@ -219,8 +221,11 @@ function onStreamRead(arrayBuffer) {
// test-https-truncate test.
if (handle.readStop) {
const err = handle.readStop();
if (err)
return stream.destroy(errnoException(err, 'read'));
if (err) {
// #34375 CallJSOnreadMethod expects the return value to be a buffer.
stream.destroy(errnoException(err, 'read'));
return;
}
}

// Push a null to signal the end of data.
Expand Down

0 comments on commit 09056fd

Please sign in to comment.