joyent/node — pull request #1868 by sbrekken (2011-10-12 10:08:19+00:00)
Title: Only register once for listening when passing a callback to Server.listen

Only register once for listening when passing a callback to Server.listen(), this prevents servers recycled using close() from invoking the callback when Server.listen() is called later.

This very simple example exposes the problem:

````javascript
var http = require('http');
var server = http.createServer();
server.on('close', function() {
console.log('Closed, listeners:', server.listeners('listening').length);
});

server.listen(3000, function() {
server.close();
server.listen(3001, function() {
server.close();
});
});
````

Output:

````
Closed, listeners: 1
Closed, listeners: 2
Closed, listeners: 3
````