Don't break internal loops on CancelledError when the cancel is not triggered internally (avoid CTRL-C issue on python < 3.11) #642
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.
Fix for #287
The issue comes from handling of KeyboardInterrupt before 3.11 (python/cpython@f08a191)
Before 3.11 all the tasks are cancelled when a KeyboardInterrupt is generated (https://github.com/python/cpython/blob/3.10/Lib/asyncio/runners.py#L47), leading that all internal loops are also cancelled, for example the client reader, flusher loops. Any call to nats client after a CTRL-PY will certainly timeout
In order to avoid such issue, this commit change the behaviour of CancelError inside the loop if this one is not due to internal cancel call.
The call to unsubscribe on PushSubscription is changed. Subscription loop is looking for is_closed from Subscription object, calling unsubscribe on super object of PushSubscription doesn't set correctly the flag _closed on the underlying Subscription.
I found during this work that the subscription inside _init_request_sub is never unsubscribed correctly.