Skip to content

Socket undestroy raceΒ #29708

@ronag

Description

@ronag

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions