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

don't suppress exception on aexit #232

Merged
merged 3 commits into from
Jul 18, 2023
Merged

Conversation

edenhaus
Copy link
Contributor

With #216 the "early out on disconnected" code was move from the function __aexit__ to disconnect. The disconnect function is called inside a try/except block in the function __aexit__, which suppresses the disconnected exception. This results in that the context manager exits without exception also when there was a disconnect-exception.

Example:

  • start mqtt broker
  • run a similar code:
async with Client("localhost") as client:
    async with client.messages() as messages:
        await client.subscribe("humidity/#")
        async for message in messages:
            print(message.payload)
  • shutdown broker

expection: I get some sort of exception
actual: no exception, only a log entry.

This bug was found on the upgrade from 0.16.1 to 1.0.0. Afterwards the following test was failing https://github.com/DeebotUniverse/client.py/blob/3d7467e3dcf338e9d848dd5fb3ad32a5ee7fab8e/tests/test_mqtt_client.py#L76C1-L76C1
The test test the described example above.

Copy link
Collaborator

@frederikaalund frederikaalund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Robert, thanks for opening this pull request. 👍 Let me have a look. :)

You're right. This seems like a regression. Indeed, the client should raise (the Exception that caused a disconnect) on exit. The current implementation erroneously suppresses (and logs) this disconnect exception. That's my bad; I missed it in the code review. Good thing that you had a test case for it. If you don't mind, could you implement a similar test case here in aiomqtt? 👍

In any case, I like this PR overall. I only have requests for minor changes. See my review for details. Let me know if you have any questions. Also, you need to fix the formatting/style issues (see the CI runs for details).

Thanks again for opening this pull request.

Best regards,
~Frederik

aiomqtt/client.py Outdated Show resolved Hide resolved
@edenhaus
Copy link
Contributor Author

For tests I would wait until guillotinaweb/pytest-docker-fixtures#33 is merged, than we have a moquitto docker container for tests. This would also fix #224

Are you fine to merge it without tests? So I can upgrade my lib to the new version and get rid of the log message about the rename

@codecov
Copy link

codecov bot commented Jul 15, 2023

Codecov Report

Merging #232 (3ef2c23) into main (9366b32) will decrease coverage by 7.1%.
The diff coverage is 81.8%.

@@           Coverage Diff           @@
##            main    #232     +/-   ##
=======================================
- Coverage   91.5%   84.5%   -7.1%     
=======================================
  Files          6       4      -2     
  Lines        843     466    -377     
  Branches     179      86     -93     
=======================================
- Hits         772     394    -378     
  Misses        46      46             
- Partials      25      26      +1     
Impacted Files Coverage Δ
aiomqtt/__init__.py 100.0% <ø> (ø)
aiomqtt/error.py 100.0% <ø> (ø)
aiomqtt/types.py 100.0% <ø> (ø)
aiomqtt/client.py 83.1% <81.8%> (ø)

... and 3 files with indirect coverage changes

@empicano
Copy link
Owner

Hi Robert, I'll ping @frederikaalund here; Maybe this got lost 😉

As a quick fix to getting rid of the log message about the rename you could restrict the version of asyncio-mqtt to <= 0.16.1. Version 0.16.1 is exactly the same as 0.16.2 apart from the log message.

@frederikaalund
Copy link
Collaborator

Thanks for the ping, @empicano. Been a busy week at work due to technical issues. :)

In any case, this PR now looks good to me. 👍 Sorry about the delay in my response.

For tests I would wait until guillotinaweb/pytest-docker-fixtures#33 is merged, than we have a moquitto docker container for tests. This would also fix #224

Are you fine to merge it without tests? So I can upgrade my lib to the new version and get rid of the log message about the rename

Yes, that's completely fine with me.

Thank you for your contribution to aiomqtt.

@frederikaalund frederikaalund merged commit 132c9f9 into empicano:main Jul 18, 2023
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 this pull request may close these issues.

3 participants