GeezerVison is showing github.com — net: fix crash if POLLHUP is received · nodejs/node@ff5ab6f
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/stream_base.cc +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -508,13 +508,21 @@ uv_buf_t CustomBufferJSListener::OnStreamAlloc(size_t suggested_size) { |
508 | 508 |
|
509 | 509 | void CustomBufferJSListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf) { |
510 | 510 | CHECK_NOT_NULL(stream_); |
511 | | - CHECK_EQ(buf.base, buffer_.base); |
512 | 511 |
|
513 | 512 | StreamBase* stream = static_cast<StreamBase*>(stream_); |
514 | 513 | Environment* env = stream->stream_env(); |
515 | 514 | HandleScope handle_scope(env->isolate()); |
516 | 515 | Context::Scope context_scope(env->context()); |
517 | 516 |
|
| 517 | + // To deal with the case where POLLHUP is received and UV_EOF is returned, as |
| 518 | + // libuv returns an empty buffer (on unices only). |
| 519 | + if (nread == UV_EOF && buf.base == nullptr) { |
| 520 | + stream->CallJSOnreadMethod(nread, Local<ArrayBuffer>()); |
| 521 | + return; |
| 522 | + } |
| 523 | + |
| 524 | + CHECK_EQ(buf.base, buffer_.base); |
| 525 | + |
518 | 526 | MaybeLocal<Value> ret = stream->CallJSOnreadMethod(nread, |
519 | 527 | Local<ArrayBuffer>(), |
520 | 528 | 0, |
|