-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
net: do not add multiple connect and finish listeners when multiple Socket.destroySoon's were scheduled
#60469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 9 commits
6e33069
9905cfb
afe8307
565e2c2
94edac0
e5ec2a4
ae5739e
a70ef63
a63fb37
40ef455
c2e85a0
3d238a0
81ac752
f703403
7b5a01a
c9a2c5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| 'use strict'; | ||
| require('../common'); | ||
| const { addresses } = require('../common/internet'); | ||
|
|
||
| const assert = require('assert'); | ||
| const net = require('net'); | ||
|
|
||
| const socket = new net.Socket(); | ||
| socket.on('error', () => { | ||
| // noop | ||
| }); | ||
| const connectOptions = { host: addresses.INVALID_HOST, port: 1234 }; | ||
|
|
||
| socket.connect(connectOptions); | ||
| socket.destroySoon(); // Adds "connect" and "finish" event listeners when socket has "writable" state | ||
| socket.destroy(); // Makes imideditly socket again "writable" | ||
|
|
||
| socket.connect(connectOptions); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what actually makes the socket writable again as it calls const net = require('net');
const options = {
host: 'example.com',
port: 80,
lookup() {}
};
const socket = new net.Socket();
socket.connect(options);
socket.read();
socket.destroy();
socket.connect(options);
socket.read();
socket.destroy();
socket.connect(options);
socket.read();
socket.destroy();
console.log(socket.listenerCount('connect')); // Prints 3
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank You for Your review! But do You think that mentioned issue should be even addressed? If yes I will analyze it deeper to provide better test that is reproducing this issue.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should fix the issue where multiple
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've removed changes for |
||
| socket.destroySoon(); // Should not duplicate "connect" and "finish" event listeners | ||
|
|
||
| assert.strictEqual(socket.listeners('finish').length, 1); | ||
| assert.strictEqual(socket.listeners('connect').length, 1); | ||
Uh oh!
There was an error while loading. Please reload this page.