From f910f645b943c908cb7b0acf704d427d0fb9f881 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 9 Jan 2020 19:31:05 +0100 Subject: [PATCH] http2: skip creating native ShutdownWrap `ShutdownWrap` instances are being used to carry context between the start and the asynchronous end of shutting down the writable side of a `StreamBase`. HTTP/2 streams always perform this action synchronously, so no such object is necessary. PR-URL: https://github.com/nodejs/node/pull/31283 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Yongsheng Zhang Reviewed-By: Rich Trott --- src/node_http2.cc | 6 ++++++ src/node_http2.h | 1 + src/stream_base-inl.h | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/node_http2.cc b/src/node_http2.cc index e467ca0e63dbb5..cf83a1c612b5b5 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -1987,6 +1987,12 @@ void Http2Stream::Close(int32_t code) { Debug(this, "closed with code %d", code); } +ShutdownWrap* Http2Stream::CreateShutdownWrap(v8::Local object) { + // DoShutdown() always finishes synchronously, so there's no need to create + // a structure to store asynchronous context. + return nullptr; +} + int Http2Stream::DoShutdown(ShutdownWrap* req_wrap) { if (IsDestroyed()) return UV_EPIPE; diff --git a/src/node_http2.h b/src/node_http2.h index 858cf30d556af7..10a894eb653b20 100644 --- a/src/node_http2.h +++ b/src/node_http2.h @@ -472,6 +472,7 @@ class Http2Stream : public AsyncWrap, int ReadStop() override; // Required for StreamBase + ShutdownWrap* CreateShutdownWrap(v8::Local object) override; int DoShutdown(ShutdownWrap* req_wrap) override; bool HasWantsWrite() const override { return true; } diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index 65af037d152763..f89eb3a5287939 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -162,7 +162,7 @@ inline int StreamBase::Shutdown(v8::Local req_wrap_obj) { ShutdownWrap* req_wrap = CreateShutdownWrap(req_wrap_obj); int err = DoShutdown(req_wrap); - if (err != 0) { + if (err != 0 && req_wrap != nullptr) { req_wrap->Dispose(); }