mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
Async iteration left the writable side of `allowHalfOpen` duplexes open
after clean EOF. For `net.Socket` instances, this retained a live handle
after the peer disconnected.
Restore default iterator destruction. Callers that need to continue
writing can use `iterator({ destroyOnReturn: false })`.
Assisted-by: Codex
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/65986
Fixes: https://github.com/nodejs/node/issues/65110
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
42 lines
846 B
JavaScript
42 lines
846 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const {
|
|
Duplex,
|
|
} = require('stream');
|
|
|
|
{
|
|
let written = '';
|
|
|
|
const duplex = new Duplex({
|
|
allowHalfOpen: true,
|
|
read() {
|
|
this.push('hello');
|
|
this.push(null);
|
|
},
|
|
write(chunk, encoding, callback) {
|
|
written += chunk;
|
|
callback();
|
|
},
|
|
});
|
|
|
|
duplex.on('error', common.mustNotCall());
|
|
duplex.on('close', common.mustCall());
|
|
|
|
(async () => {
|
|
let read = '';
|
|
for await (const chunk of duplex.iterator({ destroyOnReturn: false })) {
|
|
read += chunk;
|
|
}
|
|
|
|
assert.strictEqual(read, 'hello');
|
|
assert.strictEqual(duplex.destroyed, false);
|
|
|
|
duplex.write('world', common.mustSucceed(() => {
|
|
assert.strictEqual(written, 'world');
|
|
duplex.end();
|
|
}));
|
|
})().then(common.mustCall());
|
|
}
|