Skip to content

Commit dd74601

Browse files
santigimenotargos
authored andcommitted
net: fix crash if POLLHUP is received
If the `onread` socket option is used and a `POLLHUP` event is received, libuv returns `UV_EOF` along with a `NULL` buffer in the read callback, causing the crash. Deal with this case. Fixes: #31823 PR-URL: #32590 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 1fb4f9d commit dd74601

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/stream_base.cc

+9-1
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,21 @@ uv_buf_t CustomBufferJSListener::OnStreamAlloc(size_t suggested_size) {
517517

518518
void CustomBufferJSListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf) {
519519
CHECK_NOT_NULL(stream_);
520-
CHECK_EQ(buf.base, buffer_.base);
521520

522521
StreamBase* stream = static_cast<StreamBase*>(stream_);
523522
Environment* env = stream->stream_env();
524523
HandleScope handle_scope(env->isolate());
525524
Context::Scope context_scope(env->context());
526525

526+
// To deal with the case where POLLHUP is received and UV_EOF is returned, as
527+
// libuv returns an empty buffer (on unices only).
528+
if (nread == UV_EOF && buf.base == nullptr) {
529+
stream->CallJSOnreadMethod(nread, Local<ArrayBuffer>());
530+
return;
531+
}
532+
533+
CHECK_EQ(buf.base, buffer_.base);
534+
527535
MaybeLocal<Value> ret = stream->CallJSOnreadMethod(nread,
528536
Local<ArrayBuffer>(),
529537
0,

0 commit comments

Comments
 (0)