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

Tortoise.Registry does not clean up when a connection is closed. #147

Open
Baronozone opened this issue Jan 21, 2025 · 3 comments
Open

Tortoise.Registry does not clean up when a connection is closed. #147

Baronozone opened this issue Jan 21, 2025 · 3 comments

Comments

@Baronozone
Copy link

The Tortoise.Registry looks like it is not monitoring new Connection processes, so if they fail (or are simply closed) the information is still retained in the registry. This happens regardless of using start_link to create the connection or if you use the Tortoise.Supervisor to create the connection and close it with DynamicSupervisor.terminate_child(Tortoise.Supervisor, connection_pid). If the client_id remains the same, a new connection will not create a new entry, but in our use case we make many transient connections over time, and each has a unique client_id. So the failure to remove unused entries causes a long-term memory leak essentially.

Is there a way to remove unused entries in the Tortoise.Registry? It might be preferable to have the registry monitor the connections and remove any entries automagically, as other registries do.

@Baronozone
Copy link
Author

I have found something of a work-around for this issue. If I create something of a supervisory process, which uses start_link to create the Tortoise.Connection.start_link, and this process is trapping exits, I can call the following to clean up the Tortoise.Registry entries when the connection fails or the supervising process closes in it's terminate function:

via_used = Tortoise.Connection.via_name(my_client_id)
Tortoise.Registry.delete_meta(via_used)

@brianmay
Copy link

I think you will have more like with this fork: https://github.com/smartrent/tortoise311/

This project hasn't had any updates in the last 4 years.

@Baronozone
Copy link
Author

@brianmay -- thanks, I'll look it over. No need for MQTT 5 support anyway, and it looks like work is being done on it, which is a good sign!

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

No branches or pull requests

2 participants