Skip to content

Improve handling of closed connections#148

Merged
johnsca merged 9 commits intomasterfrom
bug/147-connection-closed
Jun 22, 2017
Merged

Improve handling of closed connections#148
johnsca merged 9 commits intomasterfrom
bug/147-connection-closed

Conversation

@johnsca
Copy link
Copy Markdown
Contributor

@johnsca johnsca commented Jun 20, 2017

This fixes #147 by closing the watcher gracefully when the connection is closed unexpectedly so that the Monitor can report it as intended. It also fixes a circular reference between the Connection and Monitor, improves the logic in the monitor status, and makes Model.block_until raise a websockets.ConnectionClosed exception instead of blocking indefinitely.

Edit: Also fixes conjure-up/conjure-up#965

johnsca added 4 commits June 19, 2017 17:07
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.
Copy link
Copy Markdown

@adam-stokes adam-stokes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

johnsca added 2 commits June 20, 2017 18:29
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.
Copy link
Copy Markdown

@adam-stokes adam-stokes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 On the restarting of the watcher

@johnsca johnsca force-pushed the bug/147-connection-closed branch from c8bb24b to d22497a Compare June 22, 2017 14:22
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chancel -> chance

@johnsca johnsca force-pushed the bug/147-connection-closed branch from 55b5d77 to bb11459 Compare June 22, 2017 15:40
@johnsca johnsca merged commit cd48f18 into master Jun 22, 2017
@johnsca johnsca deleted the bug/147-connection-closed branch April 1, 2019 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JujuAPIError: watcher was stopped Watcher dies with uncatchable ConnectionClosed error

2 participants