Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

socket.on('error') with socket.destroy() emits 'close' event twice #2223

Closed
baalexander opened this Issue · 2 comments

2 participants

@baalexander

The following code will trigger the 'close' event twice on a socket in node v0.6.x. The close event was only fired once with v0.4.x. This was tested with Ubuntu and Mac OS X.

var net    = require('net')
  , Socket = net.Socket;

var socket = new Socket();

socket.on('error', function(exception) {
  console.log('SOCKET ERROR');
  socket.destroy();
})

socket.on('close', function(exception) {
  console.log('SOCKET CLOSED');
})

socket.connect(9000, 'localhost');

Output:

SOCKET ERROR
SOCKET CLOSED
SOCKET CLOSED

I can easily just not call socket.destroy() and the 'close' event will only be emitted once. However, I thought it was worth bringing up as this wasn't the case in v0.4.x and may be a regression issue.

@bnoordhuis bnoordhuis closed this issue from a commit
@bnoordhuis bnoordhuis net: don't emit 'close' event twice
Don't allow `socket.destroy()` to run twice. The self-destruct sequence itself
is idempotent but it makes the 'close' and 'error' events fire more than once,
which may confuse listeners.

Fixes #2223.
03eb41c
@bnoordhuis bnoordhuis closed this in 03eb41c
@bnoordhuis

Thanks for the report. It's fixed in 03eb41c.

@baalexander

Thanks @bnoordhuis for the quick response!

@alexkwolfe alexkwolfe referenced this issue from a commit in alexkwolfe/node
@bnoordhuis bnoordhuis net: don't emit 'close' event twice
Don't allow `socket.destroy()` to run twice. The self-destruct sequence itself
is idempotent but it makes the 'close' and 'error' events fire more than once,
which may confuse listeners.

Fixes #2223.
1821bb5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.