diff --git a/TODO b/TODO index 9fc5c0b1ba..58def8d6b6 100644 --- a/TODO +++ b/TODO @@ -25,3 +25,4 @@ based on size but rather read until EOF into a chain of buffers, then concat them together. - process object should be defined in src/node.js not in c++ +- Test for EMFILE accept spin bug. diff --git a/lib/net.js b/lib/net.js index 97c88a8ef5..3edce338c8 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1049,6 +1049,25 @@ function Server (listener) { self.connections = 0; + self.paused = false; + self.pauseTimeout = 1000; + + function pause () { + // We've hit the maximum file limit. What to do? + // Let's try again in 1 second. + self.watcher.stop(); + + // If we're already paused, don't do another timeout. + if (self.paused) return; + + setTimeout(function () { + self.paused = false; + // Make sure we haven't closed in the interim + if (typeof self.fd != 'number') return; + self.watcher.start(); + }, self.pauseTimeout); + } + self.watcher = new IOWatcher(); self.watcher.host = self; self.watcher.callback = function () { @@ -1056,7 +1075,10 @@ function Server (listener) { try { var peerInfo = accept(self.fd); } catch (e) { - if (e.errno == EMFILE) return; + if (e.errno == EMFILE) { + pause(); + return; + } throw e; } if (!peerInfo) return;