Skip to content
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

Socket undestroy race #29708

Closed
ronag opened this issue Sep 25, 2019 · 1 comment
Closed

Socket undestroy race #29708

ronag opened this issue Sep 25, 2019 · 1 comment

Comments

@ronag
Copy link
Member

ronag commented Sep 25, 2019

Looking at the code for Socket.connect it seems that a socket that has been destroyed can be re-used.

However, the way the code is currently written (https://github.com/nodejs/node/blob/master/lib/net.js#L929) the socket can be undestroy:ed while the socket hasn't finished destroying.

Consider the following:

const c = net.createConnection(common.PORT);
c.once('connect', () => {
 c.destroy();
 c.connect(common.PORT); // Uhoh?
});
const c = net.createConnection(common.PORT);
c.destroy();
c.connect(common.PORT); // Uhoh?
c.destroy();
c.connect(common.PORT); // Uhoh?

The socket is re-used directly after destroy and _undestroy is called, before the _destroy callback has had a chance to run causing a potentially weird undefined state.

I believe we should wait for 'close' in Socket.connect before doing anything further to the instance.

Or am I missing something? @jasnell

@ronag ronag changed the title Socket undestroy Socket undestroy race Sep 25, 2019
@ronag
Copy link
Member Author

ronag commented Mar 10, 2020

duplicate #30832

@ronag ronag closed this as completed Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant