This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
socket.on('error') with socket.destroy() emits 'close' event twice #2223
Closed
Description
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.