mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 07:19:19 +00:00

This improves error handling for streams in a few ways. 1. It ensures that no user defined methods (_read, _write, ...) are run after .destroy has been called. 2. It introduces an explicit error to tell the user if they are write to write, etc to the stream after it has been destroyed. 3. It makes streams always emit close as the last thing after they have been destroyed 4. Changes the default _destroy to not gracefully end streams. It also updates net, http2, zlib and fs to the new error handling. PR-URL: https://github.com/nodejs/node/pull/18438 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
29 lines
857 B
JavaScript
29 lines
857 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const net = require('net');
|
|
const assert = require('assert');
|
|
|
|
const server = net.createServer();
|
|
server.listen(0, common.mustCall(function() {
|
|
const port = server.address().port;
|
|
const conn = net.createConnection(port);
|
|
|
|
conn.on('connect', common.mustCall(function() {
|
|
// Test destroy returns this, even on multiple calls when it short-circuits.
|
|
assert.strictEqual(conn, conn.destroy().destroy());
|
|
conn.on('error', common.expectsError({
|
|
code: 'ERR_STREAM_DESTROYED',
|
|
message: 'Cannot call write after a stream was destroyed',
|
|
type: Error
|
|
}));
|
|
|
|
conn.write(Buffer.from('kaboom'), common.expectsError({
|
|
code: 'ERR_STREAM_DESTROYED',
|
|
message: 'Cannot call write after a stream was destroyed',
|
|
type: Error
|
|
}));
|
|
server.close();
|
|
}));
|
|
}));
|