Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix monitor leak in Xandra.Connection #351

Merged
merged 1 commit into from
Oct 30, 2023
Merged

Fix monitor leak in Xandra.Connection #351

merged 1 commit into from
Oct 30, 2023

Conversation

mattias01
Copy link
Contributor

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:

iex> Process.info(pid(0, 704 ,0), :dictionary) |> elem(1) |> Enum.take(1)
["$initial_call": {Xandra.Connection, :init, 1}]
iex> Process.info(pid(0, 704 ,0), :monitored_by) |> elem(1) |> length()
105236

By explicitly demonitoring when a reply is not guaranteed, the resource leak is fixed.

Example after fix:

iex> Process.info(pid(0, 722 ,0), :dictionary) |> elem(1) |> Enum.take(1)
["$initial_call": {Xandra.Connection, :init, 1}]
iex> Process.info(pid(0, 722 ,0), :monitored_by) |> elem(1) |> length()
0

@whatyouhide whatyouhide changed the title Fix monitor leak in Connection. Fix monitor leak in Xandra.Connection Oct 30, 2023
@whatyouhide whatyouhide merged commit c4b8fbf into whatyouhide:main Oct 30, 2023
3 of 4 checks passed
@whatyouhide
Copy link
Owner

This is a great find, thank you @mattias01 🙏 Will release 0.18.1 soon.

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.

None yet

2 participants