diff --git a/src/stream_base.cc b/src/stream_base.cc index 63b06378f7c127..d8a191dc2e5f6d 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -517,13 +517,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,