From fa691f7d95516b496d946e8f85f2a11a12094cfa Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 8 Feb 2018 18:32:32 +0100 Subject: [PATCH] src: only set JSStreamWrap write req after `write()` Otherwise `this[kCurrentWriteRequest]` is set to a value even if one of the `write` calls throws. This is needed in order not to break tests in a later commit. PR-URL: https://github.com/nodejs/node/pull/18676 Reviewed-By: Ben Noordhuis Reviewed-By: Anatoli Papirovski Reviewed-By: James M Snell --- lib/internal/wrap_js_stream.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/internal/wrap_js_stream.js b/lib/internal/wrap_js_stream.js index 1c494e57e1f9dd..aed26ed8c6976a 100644 --- a/lib/internal/wrap_js_stream.js +++ b/lib/internal/wrap_js_stream.js @@ -137,7 +137,6 @@ class JSStreamWrap extends Socket { doWrite(req, bufs) { assert.strictEqual(this[kCurrentWriteRequest], null); assert.strictEqual(this[kCurrentShutdownRequest], null); - this[kCurrentWriteRequest] = req; const handle = this._handle; const self = this; @@ -149,6 +148,9 @@ class JSStreamWrap extends Socket { this.stream.write(bufs[i], done); this.stream.uncork(); + // Only set the request here, because the `write()` calls could throw. + this[kCurrentWriteRequest] = req; + function done(err) { if (!err && --pending !== 0) return;