Safely stop agent heartbeat and handle Disconnected exception #419
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 PR adds a check to make sure the heartbeat is still running before trying to stop the looping call,
self.heartbeat_call
. We also add exception handling for theautobahn.exception.Disconnected
exception we've been seeing occasionally when an agent loses its connection to the crossbar server and goes to flush its feed buffer.Motivation and Context
If an agent loses its connection to the crossbar server the heartbeat looping call might crash before it is stopped when
onLeave()
is triggered. This hits an assertion error in twisted.Additionally, when the agent goes to flush its buffer by publishing any data it has that publish call will fail with an
autobahn.exception.Disconnected
exception. We were already handling theTransportLost
exception, so we just addDisconnected
.An example of hitting both of these at the same time can be see in #417.
Resolves #417.
How Has This Been Tested?
I haven't been able to reproduce #417 locally. I've tried by running a small ocs network with the registry and several fake data agents. I then cycle the crossbar server over and over again, hoping to hit the exception just right. Cycling a couple dozen times never hit it.
I'm still going to try to think of a way to reproduce this, but wanted to get the PR open.
Types of changes
Checklist: