summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvery Pennarun <apenwarr@gmail.com>2010-12-31 21:32:51 -0800
committerAvery Pennarun <apenwarr@gmail.com>2010-12-31 21:32:51 -0800
commitb1edb226a5a2c5618ecb92e35c42cedb9bfb62c8 (patch)
tree49070d55bf7f9e593311b21e3d154f59ccf1ace6
parent41fd0348eb8f27d9c47d0b51c49fbf92d769ab5b (diff)
"Too many open files" shouldn't be a fatal condition.
It can happen if there are too many sockets open. If that happens, just throw away any connections that arrive in the meantime instead of aborting completely.
-rw-r--r--client.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/client.py b/client.py
index 0301ca0..158a873 100644
--- a/client.py
+++ b/client.py
@@ -4,6 +4,7 @@ import helpers, ssnet, ssh
from ssnet import SockWrapper, Handler, Proxy, Mux, MuxWrapper
from helpers import *
+_extra_fd = os.open('/dev/null', os.O_RDONLY)
def original_dst(sock):
try:
@@ -153,7 +154,22 @@ def _main(listener, fw, ssh_cmd, remotename, python, seed_hosts, auto_nets):
mux.got_host_list = onhostlist
def onaccept():
- sock,srcip = listener.accept()
+ global _extra_fd
+ try:
+ sock,srcip = listener.accept()
+ except socket.error, e:
+ if e.args[0] in [errno.EMFILE, errno.ENFILE]:
+ debug1('Rejected incoming connection: too many open files!\n')
+ # free up an fd so we can eat the connection
+ os.close(_extra_fd)
+ try:
+ sock,srcip = listener.accept()
+ sock.close()
+ finally:
+ _extra_fd = os.open('/dev/null', os.O_RDONLY)
+ return
+ else:
+ raise
dstip = original_dst(sock)
debug1('Accept: %r:%r -> %r:%r.\n' % (srcip[0],srcip[1],
dstip[0],dstip[1]))