Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client connection close bug due to asyncio Task set_exception deprecated #208

Open
shipmints opened this issue Feb 17, 2020 · 2 comments
Open

Comments

@shipmints
Copy link
Contributor

set_exception was removed from asyncio some time ago per https://bugs.python.org/issue32363

The modern implementation, which simply pukes a RuntimeErrror...

def set_exception(self, exception):
        raise RuntimeError('Task does not support set_exception operation')

...causes handle_connection_close cancel_tasks loop to fail on the first set_exception call. It's not clear what this loop is trying to accomplish since it isn't canceling any pending tasks.

    @asyncio.coroutine
    def handle_connection_close(self):
        def cancel_tasks():
            self._no_more_connections.set()
            while self.client_tasks:
                task = self.client_tasks.popleft()
                if not task.done():
                    task.set_exception(ClientException("Connection lost")) # BOOM THE LOOP EXITS AND EXCEPTION PROPAGATED

Perhaps it should be?

        self._no_more_connections.set() // moved from above
        if self.config.get('auto_reconnect', False):
            # Try reconnection
            self.logger.debug("Auto-reconnecting")
            try:
                yield from self.reconnect()
            except ConnectException:
                # Cancel client pending tasks
                # REPLACE? cancel_tasks()
                yield from self.cancel_tasks()
        else:
            # Cancel client pending tasks
            # REPLACE? cancel_tasks()
            yield from self.cancel_tasks()
@damouse
Copy link

damouse commented Feb 28, 2020

I'm running into the same problem. This causes deliver_message to hang instead of raising to indicate the connection closed.

Shipmint's suggestion above seems to fix the issue.

@Zamony
Copy link

Zamony commented Apr 5, 2022

I am getting the same error with hbmqtt==0.9.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants