Files
node/test/parallel/test-stream-readable-async-iter-half-open-duplex.js
Matteo Collina 795585e87e stream: destroy half-open sockets after iteration
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>
2026-09-18 05:37:18 +00:00

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());
}