Why does kazoo throw a SessionExpiredError when in KeeperState.CONNECTING state?

25 views
Skip to first unread message

jayanth kalyanasundaram

unread,
Aug 21, 2019, 9:32:52 PM8/21/19
to python-zk
In: https://github.com/python-zk/kazoo/blob/master/kazoo/client.py#L598 
    def _call(self, request, async_object):
        """Ensure there's an active connection and put the request in
        the queue if there is.

        Returns False if the call short circuits due to AUTH_FAILED,
        CLOSED, EXPIRED_SESSION or CONNECTING state.

        """

        if self._state == KeeperState.AUTH_FAILED:
            async_object.set_exception(AuthFailedError())
            return False
        elif self._state == KeeperState.CLOSED:
            async_object.set_exception(ConnectionClosedError(
                "Connection has been closed"))
            return False
        elif self._state in (KeeperState.EXPIRED_SESSION,
                             KeeperState.CONNECTING):
            async_object.set_exception(SessionExpiredError())
            return False

it looks like kazoo throws a SessionExpiredError whenever the state is in KeeperState.CONNECTING. Shouldn't it throw a ConnectionLoss in this case instead. My understanding is that SessionExpired should be thrown only when the session timeout has expired and other cases like when the client disconnected and reconnects due to a network issue etc. should just throw a ConnectionLoss error. This behavior is already being followed in https://github.com/python-zk/kazoo/blob/master/kazoo/client.py#L546:
    def _notify_pending(self, state):
        """Used to clear a pending response queue and request queue
        during connection drops."""
        if state == KeeperState.AUTH_FAILED:
            exc = AuthFailedError()
        elif state == KeeperState.EXPIRED_SESSION:
            exc = SessionExpiredError()
        else:
            exc = ConnectionLoss()

where the exception thrown is ConnectionLoss by default. SessionExpired is only thrown when the state is KeeperState.EXPIRED_SESSION.

Is the first case a bug?
Reply all
Reply to author
Forward
0 new messages