# Buggy code
def onClose(self, wasClean):
    """
    Implements :func:`autobahn.wamp.interfaces.ITransportHandler.onClose`
    """
    self._transport = None

    if self._session_id:
        # fire callback and close the transport
        try:
            self.onLeave(types.CloseDetails())
        except Exception:
            self.log.failure("Exception raised in onLeave callback")

        try:
            self._router.detach(self)
        except Exception:
            pass

        self._session_id = None

    self._pending_session_id = None

    self._authid = None
    self._authrole = None
    self._authmethod = None
    self._authprovider = None


# Traceback (PMbuiltins.AttributeError)
3/2/2017 8:26:29 PM2017-03-02T20:26:29+0000 [Router         13] Unhandled error in Deferred:
3/2/2017 8:26:29 PM2017-03-02T20:26:29+0000 [Router         13]
3/2/2017 8:26:29 PMTraceback (most recent call last):
3/2/2017 8:26:29 PM  File "/usr/local/lib/python3.6/site-packages/crossbar/router/router.py", line 192, in process
3/2/2017 8:26:29 PM    self._dealer.processCall(session, msg)
3/2/2017 8:26:29 PM  File "/usr/local/lib/python3.6/site-packages/crossbar/router/dealer.py", line 464, in processCall
3/2/2017 8:26:29 PM    txaio.add_callbacks(d, on_authorize_success, on_authorize_error)
3/2/2017 8:26:29 PM  File "/usr/local/lib/python3.6/site-packages/txaio/tx.py", line 490, in add_callbacks
3/2/2017 8:26:29 PM    future.addCallbacks(callback, errback)
3/2/2017 8:26:29 PM  File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 310, in addCallbacks
3/2/2017 8:26:29 PM    self._runCallbacks()
3/2/2017 8:26:29 PM--- <exception caught here> ---
3/2/2017 8:26:29 PM  File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 653, in _runCallbacks
3/2/2017 8:26:29 PM    current.result = callback(current.result, *args, **kw)
3/2/2017 8:26:29 PM  File "/usr/local/lib/python3.6/site-packages/crossbar/router/dealer.py", line 447, in on_authorize_success
3/2/2017 8:26:29 PM    self._call(session, call, registration, authorization)
3/2/2017 8:26:29 PM  File "/usr/local/lib/python3.6/site-packages/crossbar/router/dealer.py", line 627, in _call
3/2/2017 8:26:29 PM    self._router.send(callee, invocation)
3/2/2017 8:26:29 PM  File "/usr/local/lib/python3.6/site-packages/crossbar/router/router.py", line 163, in send
3/2/2017 8:26:29 PM    session._transport.send(msg)
3/2/2017 8:26:29 PMbuiltins.AttributeError: 'NoneType' object has no attribute 'send'

# Fixed code
def onClose(self, wasClean):
    """
    Implements :func:`autobahn.wamp.interfaces.ITransportHandler.onClose`
    """
    self._transport = None

    if self._session_id:
        # fire callback and close the transport
        try:
            self.onLeave(types.CloseDetails())
        except Exception:
            self.log.failure("Exception raised in onLeave callback")

        try:
            self._router.detach(self)
        except Exception as e:
            self.log.error(
                "Failed to detach session '{}': {}".format(self._session_id, e)
            )
            self.log.debug("{tb}".format(tb=Failure().getTraceback()))

        self._session_id = None

    self._pending_session_id = None

    self._authid = None
    self._authrole = None
    self._authmethod = None
    self._authprovider = None