Skip to content

Commit

Permalink
fix: Release lock in __aexit__ only if acquired (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemanspiff2007 authored Sep 19, 2023
1 parent 5f0c94c commit aedaf14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion aiomqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,8 @@ async def __aexit__(
)
finally:
self._force_disconnect()
self._lock.release()
if self._lock.locked():
self._lock.release()


def _set_client_socket_defaults(
Expand Down
9 changes: 9 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ async def test_topic_matches() -> None:
assert not topic.matches("$test/group/a/b/c")


async def test__aexit__() -> None:
"""Test that it's possible to call __aexit__ without prior __aenter__.
This should also cover the case of an unsucessful __aenter__.
"""
client = Client(HOSTNAME)
await client.__aexit__(None, None, None)


@pytest.mark.network
async def test_multiple_messages_generators() -> None:
"""Test that multiple Client.messages() generators can be used at the same time."""
Expand Down

0 comments on commit aedaf14

Please sign in to comment.