mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
311e12b962
Previously destroy could be called multiple times causing inconsistent and hard to predict behavior. Furthermore, since the stream _destroy implementation can only be called once, the behavior of applying destroy multiple times becomes unclear. This changes so that only the first destroy() call is executed and any subsequent calls are noops. PR-URL: https://github.com/nodejs/node/pull/29197 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
25 lines
732 B
JavaScript
25 lines
732 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.mustNotCall());
|
|
|
|
conn.write(Buffer.from('kaboom'), common.expectsError({
|
|
code: 'ERR_STREAM_DESTROYED',
|
|
message: 'Cannot call write after a stream was destroyed',
|
|
name: 'Error'
|
|
}));
|
|
server.close();
|
|
}));
|
|
}));
|