Correct cleanup on repeated waiting for never arriving messages #43
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.
When calling
expect(..)
ashared_ptr
to astd::promise
is returned.Thie shared pointer is being held by both the
mav::Connection
as well as the caller. The state is being cleared in the connection, iff 1) a message arrives that fulfils the expectations or 2) there is an exception on the network.Now, if the caller excepts something that will never occur, the expectation is being held onto by the connection forever, even when the caller has long forgotten about it.
The typical case is that the caller has received a timed out while waiting for, or the expectations has gone out of scope for some other reason. In this case, this could be a resource leak.
This PR changes the internal accounting in the connection to a
std::weak_ptr
. If any message is received, and the handler stumbles upon an expired weak pointer, it is cleared from the callback map.This way we make sure that we only hold references to promises that the caller is still keeping track of.