diff --git a/src/stream_base.cc b/src/stream_base.cc index eaccfc995c745f..3f313aaeff3a44 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -508,13 +508,21 @@ uv_buf_t CustomBufferJSListener::OnStreamAlloc(size_t suggested_size) { void CustomBufferJSListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf) { CHECK_NOT_NULL(stream_); - CHECK_EQ(buf.base, buffer_.base); StreamBase* stream = static_cast(stream_); Environment* env = stream->stream_env(); HandleScope handle_scope(env->isolate()); Context::Scope context_scope(env->context()); + // To deal with the case where POLLHUP is received and UV_EOF is returned, as + // libuv returns an empty buffer (on unices only). + if (nread == UV_EOF && buf.base == nullptr) { + stream->CallJSOnreadMethod(nread, Local()); + return; + } + + CHECK_EQ(buf.base, buffer_.base); + MaybeLocal ret = stream->CallJSOnreadMethod(nread, Local(), 0,