Fix monitor leak in Xandra.Connection #351
Merged
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 prepare or execute on a connection, a monitor is started on that connection which is configured to be removed when it receives a reply using the created alias. However it does not always receive a reply using that alias, which can lead to a resource leak where monitors are created and never removed.
This is mostly (only?) a problem when calling prepare on a long running connection from a long running process when the prepared query already is in the cache, because then the connection does not send a reply using the alias. The leaked monitors eventually takes up enough memory to crash the application. In my case, after a few hours.
Example before fix:
By explicitly demonitoring when a reply is not guaranteed, the resource leak is fixed.
Example after fix: