Improve handling of closed connections#148
Merged
Conversation
Instead of the watcher task blowing up with an exception when the connection is closed, it should exit cleanly and allow the Monitor to report the connection error. Fixes #147
Rather than blocking indefinitely when waiting on a model change that will never happen if the connection gets closed out from under it, this makes `Model.block_until` raise a `websockets.ConnectionClosed` error so that it can be caught and dealt with by the client.
The receiver or all_watcher should immediately reconnect a lost connection, or it will be reconnected automatically upon issuance of the next RPC call. However, there is still a small chance that the disconnect could happen between sending a API call and receiving the response, in which case a websockets.ConnectionClosed error will still be raised to the caller. These should be quite rare, though.
adam-stokes
approved these changes
Jun 22, 2017
adam-stokes
left a comment
There was a problem hiding this comment.
+1 On the restarting of the watcher
c8bb24b to
d22497a
Compare
adam-stokes
reviewed
Jun 22, 2017
juju/model.py
Outdated
| if self._watch_stopping.is_set(): | ||
| # this shouldn't ever actually happen, because | ||
| # the event should trigger before the controller | ||
| # has a chancel to tell us the watcher is stopped |
55b5d77 to
bb11459
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This fixes #147 by closing the watcher gracefully when the connection is closed unexpectedly so that the
Monitorcan report it as intended. It also fixes a circular reference between theConnectionandMonitor, improves the logic in the monitor status, and makesModel.block_untilraise awebsockets.ConnectionClosedexception instead of blocking indefinitely.Edit: Also fixes conjure-up/conjure-up#965