Commit b1edb226 authored by Avery Pennarun's avatar Avery Pennarun

"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.
parent 41fd0348
...@@ -4,6 +4,7 @@ import helpers, ssnet, ssh ...@@ -4,6 +4,7 @@ import helpers, ssnet, ssh
from ssnet import SockWrapper, Handler, Proxy, Mux, MuxWrapper from ssnet import SockWrapper, Handler, Proxy, Mux, MuxWrapper
from helpers import * from helpers import *
_extra_fd = os.open('/dev/null', os.O_RDONLY)
def original_dst(sock): def original_dst(sock):
try: try:
...@@ -153,7 +154,22 @@ def _main(listener, fw, ssh_cmd, remotename, python, seed_hosts, auto_nets): ...@@ -153,7 +154,22 @@ def _main(listener, fw, ssh_cmd, remotename, python, seed_hosts, auto_nets):
mux.got_host_list = onhostlist mux.got_host_list = onhostlist
def onaccept(): 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) dstip = original_dst(sock)
debug1('Accept: %r:%r -> %r:%r.\n' % (srcip[0],srcip[1], debug1('Accept: %r:%r -> %r:%r.\n' % (srcip[0],srcip[1],
dstip[0],dstip[1])) dstip[0],dstip[1]))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment