Skip to content

Commit

Permalink
src: only set JSStreamWrap write req after write()
Browse files Browse the repository at this point in the history
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: #18676
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax committed Feb 14, 2018
1 parent 82c43ae commit e1271c0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/internal/wrap_js_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit e1271c0

Please sign in to comment.