diff options
author | Avery Pennarun <apenwarr@gmail.com> | 2010-12-31 21:32:51 -0800 |
---|---|---|
committer | Avery Pennarun <apenwarr@gmail.com> | 2010-12-31 21:32:51 -0800 |
commit | b1edb226a5a2c5618ecb92e35c42cedb9bfb62c8 (patch) | |
tree | 49070d55bf7f9e593311b21e3d154f59ccf1ace6 | |
parent | 41fd0348eb8f27d9c47d0b51c49fbf92d769ab5b (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.py | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -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])) |