From e4dea40ce779ae03a77c194074e5aa06a8a28a78 Mon Sep 17 00:00:00 2001 From: Ouyang Yadong Date: Sun, 7 Oct 2018 21:18:15 +0800 Subject: tls: make StreamWrap work correctly in "drain" callback When an instance of StreamWrap is shutting down and a "drain" event is emitted, the instance will abort as its `this[kCurrentShutdownRequest]` is already set. The following test will fail before this commit. PR-URL: https://github.com/nodejs/node/pull/23294 Reviewed-By: Anna Henningsen Reviewed-By: Daniel Bevenius --- lib/internal/wrap_js_stream.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/internal/wrap_js_stream.js b/lib/internal/wrap_js_stream.js index b51e008705..e6de433676 100644 --- a/lib/internal/wrap_js_stream.js +++ b/lib/internal/wrap_js_stream.js @@ -100,9 +100,6 @@ class JSStreamWrap extends Socket { } doShutdown(req) { - assert.strictEqual(this[kCurrentShutdownRequest], null); - this[kCurrentShutdownRequest] = req; - // TODO(addaleax): It might be nice if we could get into a state where // DoShutdown() is not called on streams while a write is still pending. // @@ -113,8 +110,10 @@ class JSStreamWrap extends Socket { // so for now that is supported here. if (this[kCurrentWriteRequest] !== null) - return this.on('drain', () => this.doShutdown(req)); + return this.once('drain', () => this.doShutdown(req)); assert.strictEqual(this[kCurrentWriteRequest], null); + assert.strictEqual(this[kCurrentShutdownRequest], null); + this[kCurrentShutdownRequest] = req; const handle = this._handle; -- cgit v1.2.3