Cancelling ping_server task potentially kills _conn_lost_cb execution. #43
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi there,
We were trying to implement automatic reconnection to STAN when the connection was lost, and ran into an issue with the
conn_lost_cb
.If you have a couple of awaitable, like calling
stan_client.connect
, the callback stops executing. This is due to, the whole task that is responsible for invokingconn_lost_cb
(_ping_server_task
) gets cancelled during the clean up of the client.Someone with more experience in the code-base and more knowledge of asyncio could surely improve the change. But this is sufficient to be able to implement a retry mechanism.
The fix we have introduced is a shield around
_close_due_to_ping_failure
to allow the callback to full finish its execution.The issue can easily be reproduced, by introducing an awaitable call inside
conn_lost_cb
, that is long enough for task to register it has been cancelled:Notice that this does not only affect
_conn_lost_cb
, but potentially be any of the clean up work in_close_due_to_ping_failure
after the_ping_server_task
cancellation.Cheers