From 0ba01b2ce75b716f8c14a8feb74b91d7fca5a6e6 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Thu, 19 Feb 2015 15:55:59 -0800 Subject: [PATCH] hush exception noise --- src/wormhole/blocking/transit.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/wormhole/blocking/transit.py b/src/wormhole/blocking/transit.py index ab88abc..3eb6d65 100644 --- a/src/wormhole/blocking/transit.py +++ b/src/wormhole/blocking/transit.py @@ -151,18 +151,26 @@ def handle(skt, client_address, owner, send_handshake, expected_handshake): got = b"" # for the receiver, this includes the "go\n" while len(got) < len(expected_handshake): - got += skt.recv(1) + more = skt.recv(1) + if not more: + raise BadHandshake("disconnect after merely '%r'" % got) + got += more if expected_handshake[:len(got)] != got: raise BadHandshake("got '%r' want '%r'" % (got, expected_handshake)) print "handler negotiation finished", client_address - except: + except Exception as e: + print "handler failed", client_address try: + # this raises socket.err(EBADF) if the socket was already closed skt.shutdown(socket.SHUT_WR) except socket.error: pass - skt.close() - raise + skt.close() # this appears to be idempotent + # ignore socket errors, warn about coding errors + if not isinstance(e, (socket.error, socket.timeout, BadHandshake)): + raise + return # owner is now responsible for the socket owner._negotiation_finished(skt) # note thread