From 82370705872d05c882e8e9c6584bfaed3cde3cde Mon Sep 17 00:00:00 2001 From: Tobias Oberstein Date: Sat, 5 Sep 2015 10:32:29 +0200 Subject: [PATCH] don't use .message, which is removed in Py3; better logging (fixes #479) --- autobahn/twisted/websocket.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/autobahn/twisted/websocket.py b/autobahn/twisted/websocket.py index 6fe666b3..df0fed31 100644 --- a/autobahn/twisted/websocket.py +++ b/autobahn/twisted/websocket.py @@ -33,7 +33,8 @@ from zope.interface import implementer import twisted.internet.protocol from twisted.internet.defer import maybeDeferred from twisted.internet.interfaces import ITransport -from twisted.internet.error import ConnectionDone, ConnectionAborted +from twisted.internet.error import ConnectionDone, ConnectionAborted, \ + ConnectionLost from autobahn.wamp import websocket from autobahn.websocket import protocol @@ -98,14 +99,23 @@ class WebSocketAdapterProtocol(twisted.internet.protocol.Protocol): pass def connectionLost(self, reason): - # https://twistedmatrix.com/documents/current/api/twisted.internet.error.ConnectionDone.html if isinstance(reason.value, ConnectionDone): - self.factory.log.debug("Connection from {peer} was closed cleanly", peer=self.peer) - # https://twistedmatrix.com/documents/current/api/twisted.internet.error.ConnectionAborted.html + self.factory.log.debug("Connection to/from {peer} was closed cleanly", + peer=self.peer) + elif isinstance(reason.value, ConnectionAborted): - self.factory.log.debug("Connection from {peer} was aborted locally", peer=self.peer) + self.factory.log.debug("Connection to/from {peer} was aborted locally", + peer=self.peer) + + elif isinstance(reason.value, ConnectionLost): + self.factory.log.debug("Connection to/from {peer} was lost in a non-clean fashion: {message}", + peer=self.peer, message=reason.value.args[0]) + + # at least: FileDescriptorOverrun, ConnectionFdescWentAway - but maybe others as well? else: - self.factory.log.info("Connection from {peer} was lost: {message}", peer=self.peer, message=reason.value.message) + self.factory.log.info("Connection to/from {peer} lost ({error_type}): {error})", + peer=self.peer, error_type=type(reason.value), error=reason.value) + self._connectionLost(reason) def dataReceived(self, data): @@ -113,9 +123,9 @@ class WebSocketAdapterProtocol(twisted.internet.protocol.Protocol): def _closeConnection(self, abort=False): if abort and hasattr(self.transport, 'abortConnection'): - # ProcessProtocol lacks abortConnection() self.transport.abortConnection() else: + # e.g. ProcessProtocol lacks abortConnection() self.transport.loseConnection() def _onOpen(self):