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

Wrong on_disconnect() being called for an MQTT v5 connection #570

Closed
fpagliughi opened this issue May 11, 2021 · 1 comment · Fixed by home-assistant/core#59339
Closed
Milestone

Comments

@fpagliughi
Copy link
Contributor

I have an MQTT v5 connection to Mosquitto, which I am trying to shut down cleanly as I exit the program, by calling disconnect() on the client.

I registered a callback for the disconnect as a member of a class, using the form:

    def _on_disconnect(self, cli, _userdata, rc, props):
        log.warning("MQTT client '%s' disconnected.", self.name)

But it crashes out, as it seems to be calling the v3 version of the callback:

Caught exception in on_disconnect: _on_disconnect() missing 1 required positional argument: 'props'
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/home/fmp/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 3452, in _thread_main
    self.loop_forever(retry_first_connection=True)
  File "/home/fmp/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 1779, in loop_forever
    rc = self.loop(timeout, max_packets)
  File "/home/fmp/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 1197, in loop
    rc = self.loop_write(max_packets)
  File "/home/fmp/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 1598, in loop_write
    rc = self._packet_write()
  File "/home/fmp/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 2374, in _packet_write
    self._do_on_disconnect(0)
  File "/home/fmp/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 3360, in _do_on_disconnect
    self.on_disconnect(self, self._userdata, rc)
TypeError: _on_disconnect() missing 1 required positional argument: 'props'

Am I doing something dumb here?

ralight added a commit that referenced this issue Jul 21, 2021
It would sometimes call the MQTT v3.x callback when it should
call the MQTT v5 callback.

Closes #570. Thanks to Frank Pagliughi.
@ralight
Copy link
Contributor

ralight commented Jul 21, 2021

Thanks Frank, you're not doing anything dumb - there was an incorrect check. I've fixed that in the develop branch if you fancy testing out the fix.

@ralight ralight closed this as completed Jul 21, 2021
@ralight ralight added this to the 1.6.0 milestone Jul 22, 2021
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

Successfully merging a pull request may close this issue.

2 participants