net: wait for shutdown to complete before closing · nodejs/node@3c8bf90 · GitHub
Skip to content

Commit 3c8bf90

Browse files
ronagtargos
authored andcommitted
net: wait for shutdown to complete before closing
When not allowing half open, handle.close would be invoked before shutdown has been called and completed causing a potential data race. Fixes: #32486 (comment) PR-URL: #32491 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 9ee2afa commit 3c8bf90

4 files changed

Lines changed: 39 additions & 6 deletions

File tree

lib/internal/stream_base_commons.js

Lines changed: 10 additions & 0 deletions

lib/net.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,9 @@ function onReadableStreamEnd() {
631631
this.write = writeAfterFIN;
632632
if (this.writable)
633633
this.end();
634-
}
635-
636-
if (!this.destroyed && !this.writable && !this.writableLength)
634+
else if (!this.writableLength)
635+
this.destroy();
636+
} else if (!this.destroyed && !this.writable && !this.writableLength)
637637
this.destroy();
638638
}
639639

test/async-hooks/test-graph.tls-write.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ function onexit() {
6565
{ type: 'TCPCONNECTWRAP',
6666
id: 'tcpconnect:1', triggerAsyncId: 'tcp:1' },
6767
{ type: 'TCPWRAP', id: 'tcp:2', triggerAsyncId: 'tcpserver:1' },
68-
{ type: 'TLSWRAP', id: 'tls:2', triggerAsyncId: 'tcpserver:1' },
69-
{ type: 'Immediate', id: 'immediate:1', triggerAsyncId: 'tcp:2' },
70-
{ type: 'Immediate', id: 'immediate:2', triggerAsyncId: 'tcp:1' },
68+
{ type: 'TLSWRAP', id: 'tls:2', triggerAsyncId: 'tcpserver:1' }
7169
]
7270
);
7371
}
Lines changed: 25 additions & 0 deletions

0 commit comments

Comments
 (0)