Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0c73221

Browse filesBrowse files
addaleaxcodebytere
authored andcommitted
tls: do not rely on 'drain' handlers in StreamWrap
`'drain'` event handlers may not be invoked if the stream is currently finishing. Instead, use the fact that we know when writes are active or not, and invoke the delayed shutdown handler from our own after-write callback. PR-URL: #24290 Refs: #24288 Refs: #24075 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Ouyang Yadong <oyydoibh@gmail.com>
1 parent 21843c7 commit 0c73221
Copy full SHA for 0c73221

File tree

Expand file treeCollapse file tree

1 file changed

+11
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-2
lines changed
Open diff view settings
Collapse file

‎lib/internal/wrap_js_stream.js‎

Copy file name to clipboardExpand all lines: lib/internal/wrap_js_stream.js
+11-2Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const { ERR_STREAM_WRAP } = require('internal/errors').codes;
1111

1212
const kCurrentWriteRequest = Symbol('kCurrentWriteRequest');
1313
const kCurrentShutdownRequest = Symbol('kCurrentShutdownRequest');
14+
const kPendingShutdownRequest = Symbol('kPendingShutdownRequest');
1415

1516
function isClosing() { return this[owner_symbol].isClosing(); }
1617
function onreadstart() { return this[owner_symbol].readStart(); }
@@ -79,6 +80,7 @@ class JSStreamWrap extends Socket {
7980
this.stream = stream;
8081
this[kCurrentWriteRequest] = null;
8182
this[kCurrentShutdownRequest] = null;
83+
this[kPendingShutdownRequest] = null;
8284
this.readable = stream.readable;
8385
this.writable = stream.writable;
8486

@@ -115,8 +117,10 @@ class JSStreamWrap extends Socket {
115117
// Working around that on the native side is not quite trivial (yet?),
116118
// so for now that is supported here.
117119

118-
if (this[kCurrentWriteRequest] !== null)
119-
return this.once('drain', () => this.doShutdown(req));
120+
if (this[kCurrentWriteRequest] !== null) {
121+
this[kPendingShutdownRequest] = req;
122+
return 0;
123+
}
120124
assert.strictEqual(this[kCurrentWriteRequest], null);
121125
assert.strictEqual(this[kCurrentShutdownRequest], null);
122126
this[kCurrentShutdownRequest] = req;
@@ -189,6 +193,11 @@ class JSStreamWrap extends Socket {
189193
this[kCurrentWriteRequest] = null;
190194

191195
handle.finishWrite(req, errCode);
196+
if (this[kPendingShutdownRequest]) {
197+
const req = this[kPendingShutdownRequest];
198+
this[kPendingShutdownRequest] = null;
199+
this.doShutdown(req);
200+
}
192201
}
193202

194203
doClose(cb) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.