Clean up AGWPE connection data upon termination #600
+144
−64
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.
Per-connection data for an AGWPE connection was being cleaned up only when the client itself went away, rather than when each connection was terminated. This led to reuse of stale state machine instances, which in turn led to incorrect connection attempts and statistics.
The following changes have been made to address this:
Per-connection cleanup code from dl_client_cleanup has been moved to a new function, dl_connection_cleanup. dl_client_cleanup now calls this new function from within its existing loop, walking though all connections for the client being cleaned up.
A new function, dl_connection_terminated, encapsulates the removal of a single state machine instance from the list and the cleanup of that connection instance, calling dl_connection_cleanup for the latter.
Everywhere that server_link_terminated is being called, a new call to dl_connection_terminated has been added nearby, to ensure the connection is cleaned up. The call is "nearby" because invocations of server_link_terminated differ in their surrounding calls to other timer and state functions, and the order of those calls, so simply wrapping server_link_terminated is not appropriate.
Many, but not all, existing calls to server_link_terminated have nearby calls to set the state machine state to disconnected. While this is also done in dl_connection_cleanup, the existing calls have been left to minimize disruption. (There is no real cost associated with changing state from disconnected to disconnected.)
These changes have been tested in as many situations as possible, with Direwolf started using '-d ac' to watch debug output for both AGWPE and connection / state machine related activity.
Fixes #534, Fixes #535