-
Notifications
You must be signed in to change notification settings - Fork 3
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
[email protected]: Exception from close() after connect() #91
Comments
This assertion was added by #74 to fix a mypy warning: pjrpc/pjrpc/client/backend/aio_pika.py Line 86 in 27a9630
Context: async def close(self) -> None:
"""
Closes current broker connection.
"""
+ assert self._channel is not None, "client is not initialized"
+ assert self._connection is not None, "client is not initialized"
+ assert self._result_queue is not None, "client is not initialized"
+
if self._consumer_tag:
await self._result_queue.cancel(self._consumer_tag)
self._consumer_tag = None
await self._channel.close()
await self._connection.close() |
Proposed fix: - assert self._result_queue is not None, "client is not initialized"
- if self._consumer_tag:
+ if self._consumer_tag and self._result_queue:
await self._result_queue.cancel(self._consumer_tag)
self._consumer_tag = None
await self._channel.close()
await self._connection.close() Reason: self._result_queue is not initialized by default, only when a fixed result queue is used (see the description). Also it should be possible to call close the a connection ( This could happen in some circumstances, e.g. when handling a |
Issue #91 shows an AssertionError when a connected aio_pika client which didn't need to open a result queue calls client.close(). It should be possible to call client.close() also in this case to close the connection to the RabbitMQ server, because when either the client was interrupted, had nothing to do before closing, it, this is the normal state. Also replace the other assertions in the aio_pika client's close() with simple checks which don't abort the function to close any other remaining connection elements or futures which are not properly handled when simply aborting with an assertion. For details and a test case, see issue #91.
Issue #91 shows an AssertionError when a connected aio_pika client which didn't need to open a result queue calls client.close(). It should be possible to call client.close() also in this case to close the connection to the RabbitMQ server, because when either the client was interrupted, had nothing to do before closing, it, this is the normal state. Also replace the other assertions in the aio_pika client's close() with simple checks which don't abort the function to close any other remaining connection elements or futures which are not properly handled when simply aborting with an assertion. For details and a test case, see issue #91.
@dapper91 ping |
with 1.6.0, this results in:
self._result_queue
is always none, unless the Client is costructed to use a fixed result_queue like this:But for the majority of uses, a fixed result queue is not needed and a temporary result queue is used for each call (which is easier if you want to run more than one RPC client)
The text was updated successfully, but these errors were encountered: