Skip to content
Browse files

added catchall exception; modified close_sent assertion

  • Loading branch information...
1 parent a596569 commit 3478a5f4ad7d4b022b8960792403313e672f5d0a @rhs committed Jul 27, 2011
Showing with 19 additions and 10 deletions.
  1. +4 −1 connection.py
  2. +15 −9 util.py
View
5 connection.py
@@ -39,6 +39,7 @@ def __init__(self, factory):
self.open_sent = False
self.close_rcvd = False
self.close_sent = False
+ self.exception = None
# incoming channel -> session
self.incoming = {}
@@ -48,7 +49,8 @@ def __init__(self, factory):
self.max_frame_size = 4294967295
def post_frame(self, channel, body):
- assert not self.close_sent, str(body)
+ # XXX: if we hit an error then we pretend we've sent a close
+ assert not self.close_sent or self.exception is not None, str(body)
return Dispatcher.post_frame(self, channel, body)
def opening(self):
@@ -107,6 +109,7 @@ def error(self, exc):
Dispatcher.error(self, exc)
self.close_rcvd = True
self.close_sent = True
+ self.exception = exc
def add(self, ssn):
ssn.channel = self.allocate_channel()
View
24 util.py
@@ -129,16 +129,22 @@ def readable(self, selector):
except:
cls, exc, tb = sys.exc_info()
self.connection.trace("err", "".join(traceback.format_exception(cls, exc, tb)).strip())
- self.connection.error(exc)
- self.tick(self.connection)
- else:
- if bytes:
- self.connection.write(bytes)
- self.tick(self.connection)
- return
- else:
- self.connection.closed()
+ try:
+ self.connection.error(exc)
self.tick(self.connection)
+ except:
+ self.connection.trace("err", traceback.format_exc().strip())
+ else:
+ try:
+ if bytes:
+ self.connection.write(bytes)
+ self.tick(self.connection)
+ return
+ else:
+ self.connection.closed()
+ self.tick(self.connection)
+ except:
+ self.connection.trace("err", traceback.format_exc().strip())
selector.unregister(self)
self.socket.close()
self.socket = None

0 comments on commit 3478a5f

Please sign in to comment.
Something went wrong with that request. Please try again.