GeezerVison is showing github.com — net: wait for shutdown to complete before closing · nodejs/node@3c8bf90
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/stream_base_commons.js +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -213,6 +213,16 @@ function onStreamRead(arrayBuffer) { | 213 | 213 | if (stream[kMaybeDestroy]) | 214 | 214 | stream.on('end', stream[kMaybeDestroy]); | 215 | 215 |
| | 216 | + // TODO(ronag): Without this `readStop`, `onStreamRead` | | 217 | + // will be called once more (i.e. after Readable.ended) | | 218 | + // on Windows causing a ECONNRESET, failing the | | 219 | + // test-https-truncate test. | | 220 | + if (handle.readStop) { | | 221 | + const err = handle.readStop(); | | 222 | + if (err) | | 223 | + return stream.destroy(errnoException(err, 'read')); | | 224 | + } | | 225 | + | 216 | 226 | // Push a null to signal the end of data. | 217 | 227 | // Do it before `maybeDestroy` for correct order of events: | 218 | 228 | // `end` -> `close` | |
Collapse file Copy file name to clipboardExpand all lines: lib/net.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -631,9 +631,9 @@ function onReadableStreamEnd() { | 631 | 631 | this.write = writeAfterFIN; | 632 | 632 | if (this.writable) | 633 | 633 | 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) | 637 | 637 | this.destroy(); | 638 | 638 | } | 639 | 639 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/async-hooks/test-graph.tls-write.js +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -65,9 +65,7 @@ function onexit() { | 65 | 65 | { type: 'TCPCONNECTWRAP', | 66 | 66 | id: 'tcpconnect:1', triggerAsyncId: 'tcp:1' }, | 67 | 67 | { 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' } | 71 | 69 | ] | 72 | 70 | ); | 73 | 71 | } |
Collapse file Copy file name to clipboard +25Lines changed: 25 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | + | | 3 | +const common = require('../common'); | | 4 | +const assert = require('assert'); | | 5 | +const net = require('net'); | | 6 | + | | 7 | +const server = net.createServer(common.mustCall((socket) => { | | 8 | + socket.end(Buffer.alloc(1024)); | | 9 | +})).listen(0, common.mustCall(() => { | | 10 | + const socket = net.connect(server.address().port); | | 11 | + assert.strictEqual(socket.allowHalfOpen, false); | | 12 | + socket.resume(); | | 13 | + socket.on('end', common.mustCall(() => { | | 14 | + process.nextTick(() => { | | 15 | + // Ensure socket is not destroyed straight away | | 16 | + // without proper shutdown. | | 17 | + assert(!socket.destroyed); | | 18 | + server.close(); | | 19 | + }); | | 20 | + })); | | 21 | + socket.on('finish', common.mustCall(() => { | | 22 | + assert(!socket.destroyed); | | 23 | + })); | | 24 | + socket.on('close', common.mustCall()); | | 25 | +})); |
|