From 7153bec9552438227e76dc1f51e84fb34ec841ff Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 24 Mar 2018 23:12:22 +0100 Subject: [PATCH] src: always call ReadStop() before Close() For libuv-backed streams, always explicitly stop reading before closing the handle. PR-URL: https://github.com/nodejs/node/pull/19377 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- src/handle_wrap.h | 3 ++- src/stream_wrap.cc | 5 +++++ src/stream_wrap.h | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/handle_wrap.h b/src/handle_wrap.h index fd2d002dce0338..b2b09f5010d1f7 100644 --- a/src/handle_wrap.h +++ b/src/handle_wrap.h @@ -70,7 +70,8 @@ class HandleWrap : public AsyncWrap { inline uv_handle_t* GetHandle() const { return handle_; } - void Close(v8::Local close_callback = v8::Local()); + virtual void Close( + v8::Local close_callback = v8::Local()); protected: HandleWrap(Environment* env, diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index 0e700ba39a6b95..cdcbe574f9ae5f 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -373,6 +373,11 @@ void LibuvStreamWrap::AfterUvWrite(uv_write_t* req, int status) { req_wrap->Done(status); } +void LibuvStreamWrap::Close(v8::Local close_callback) { + ReadStop(); + HandleWrap::Close(close_callback); +} + } // namespace node NODE_BUILTIN_MODULE_CONTEXT_AWARE(stream_wrap, diff --git a/src/stream_wrap.h b/src/stream_wrap.h index 7847ebe754614a..94a161b6d54e07 100644 --- a/src/stream_wrap.h +++ b/src/stream_wrap.h @@ -76,6 +76,8 @@ class LibuvStreamWrap : public HandleWrap, public StreamBase { ShutdownWrap* CreateShutdownWrap(v8::Local object) override; WriteWrap* CreateWriteWrap(v8::Local object) override; + void Close(v8::Local close_callback) override; + protected: LibuvStreamWrap(Environment* env, v8::Local object,