Skip to content
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,13 +795,20 @@ function onReadableStreamEnd() {


Socket.prototype.destroySoon = function() {
if (this.destroyingOnFinish) return;

if (this.writable)
this.end();

if (this.writableFinished)
this.destroy();
else
this.once('finish', this.destroy);
else {
this.destroyingOnFinish = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use a Symbol for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right 👍 Symbol used ✅

this.once('finish', () => {
this.destroyingOnFinish = false;
this.destroy();
});
}
};


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';
require('../common');

const assert = require('assert');
const { Socket } = require('net');

const socket = new Socket();
socket.destroySoon();
socket.destroySoon();
assert.strictEqual(socket.listeners('finish').length, 1);
Loading