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 <info@bnoordhuis.nl>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Anna Henningsen 2018-02-08 18:32:32 +01:00
parent 82c43aed16
commit e1271c07c3
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9

View File

@ -137,7 +137,6 @@ class JSStreamWrap extends Socket {
doWrite(req, bufs) { doWrite(req, bufs) {
assert.strictEqual(this[kCurrentWriteRequest], null); assert.strictEqual(this[kCurrentWriteRequest], null);
assert.strictEqual(this[kCurrentShutdownRequest], null); assert.strictEqual(this[kCurrentShutdownRequest], null);
this[kCurrentWriteRequest] = req;
const handle = this._handle; const handle = this._handle;
const self = this; const self = this;
@ -149,6 +148,9 @@ class JSStreamWrap extends Socket {
this.stream.write(bufs[i], done); this.stream.write(bufs[i], done);
this.stream.uncork(); this.stream.uncork();
// Only set the request here, because the `write()` calls could throw.
this[kCurrentWriteRequest] = req;
function done(err) { function done(err) {
if (!err && --pending !== 0) if (!err && --pending !== 0)
return; return;