Browse Source

net: register net.Server callback only once

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.
v0.7.4-release
Simen Brekken 13 years ago
committed by Ben Noordhuis
parent
commit
4b0e36810a
  1. 2
      lib/net.js
  2. 19
      test/simple/test-net-server-listen-remove-callback.js

2
lib/net.js

@ -698,7 +698,7 @@ Server.prototype.listen = function() {
var lastArg = arguments[arguments.length - 1];
if (typeof lastArg == 'function') {
self.addListener('listening', lastArg);
self.once('listening', lastArg);
}
var port = toPort(arguments[0]);

19
test/simple/test-net-server-listen-remove-callback.js

@ -0,0 +1,19 @@
var common = require('../common');
var assert = require('assert');
var net = require('net');
// Server should only fire listen callback once
var server = net.createServer();
server.on('close', function() {
var listeners = server.listeners('listening');
console.log('Closed, listeners:', listeners.length);
assert.equal(0, listeners.length);
});
server.listen(3000, function() {
server.close();
server.listen(3001, function() {
server.close();
});
});
Loading…
Cancel
Save