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.
Description
This is a proposal to fix this issue.
FIX 1
The first step is to edit stray_cat.py:
Basically, we add a try-except block to the original code (
run
method) to handle the problem:It catches the ConnectionClosedOK exception, and, it logs a warning using log.warning(ex).
Then, if the
ConnectionClosedOK
exception is caught, it deletes theself.__ws
variable and sets it toNone
.In the screencast below we can observe how the fix works against reproduce.py:
FIX 2
The first fix is used to handle this specific case: a given user closes the connection while the Cat is still providing an answer.
In case of a hypothetical different flow, we would run into the same problem again.
To avoid this, we can generalize the fix, adding this try-except block to the async method
get_user_stray
in connection.py:This fix ensure that, if we get a RuntimeError from WebSocket, we get a warning, and the stray, that once again is an inconsistent state, is cleaned up (same strategy we used for the first fix).
To avoid using a private attribute, we could extract this and implement a new method in the
StrayCat
class:In the screencast below, again, we can see how the second fix works against reproduce.py:
Related to this issue
Type of change
Checklist:
I did not commented my code, I think it is not needed in this case.
As always, thanks for your work and support/review.