Skip to content

Commit

Permalink
src: always call ReadStop() before Close()
Browse files Browse the repository at this point in the history
For libuv-backed streams, always explicitly stop reading before
closing the handle.

PR-URL: #19377
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax committed May 10, 2018
1 parent 5d70459 commit 2b31504
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/handle_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class HandleWrap : public AsyncWrap {

inline uv_handle_t* GetHandle() const { return handle_; }

void Close(v8::Local<v8::Value> close_callback = v8::Local<v8::Value>());
virtual void Close(
v8::Local<v8::Value> close_callback = v8::Local<v8::Value>());

protected:
HandleWrap(Environment* env,
Expand Down
5 changes: 5 additions & 0 deletions src/stream_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ void LibuvStreamWrap::AfterUvWrite(uv_write_t* req, int status) {
req_wrap->Done(status);
}

void LibuvStreamWrap::Close(v8::Local<v8::Value> close_callback) {
ReadStop();
HandleWrap::Close(close_callback);
}

} // namespace node

NODE_BUILTIN_MODULE_CONTEXT_AWARE(stream_wrap,
Expand Down
2 changes: 2 additions & 0 deletions src/stream_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class LibuvStreamWrap : public HandleWrap, public StreamBase {
ShutdownWrap* CreateShutdownWrap(v8::Local<v8::Object> object) override;
WriteWrap* CreateWriteWrap(v8::Local<v8::Object> object) override;

void Close(v8::Local<v8::Value> close_callback) override;

protected:
LibuvStreamWrap(Environment* env,
v8::Local<v8::Object> object,
Expand Down

0 comments on commit 2b31504

Please sign in to comment.