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

Keep track of background tasks and clean them up when the spawning struct is dropped #286

Open
LeeSmet opened this issue Jun 5, 2024 · 0 comments
Labels
type_feature New feature or request

Comments

@LeeSmet
Copy link
Contributor

LeeSmet commented Jun 5, 2024

We are spawning a bunch of (background) tasks in the code (router and peer manager mostly) which essentially run forever (some could exit if the channel they reach from gets closed, but that generally won't happen as we keep the channels on the same struct). These tasks also keep a copy of the containing struct locally to access it, either through an Arc or a deep copy.

We'll need a way to track these background tasks and abort them when required. Keeping track can be done by shoving them in an Arc<Mutex<Vec>> (since this is strictly for cancelling the tasks, we track the aborthandle instead of the joinhandle as that more clearly describes the intention and there is no need for the result). For cancelling them, using the Drop trait will probably not work due to the amount of Arc's and Clones which are kept. This can be exposed as a terminate method of sorts which aborts all tasks. Using a cancellation token and injecting that into tasks is technically also possible, but also requires a way to cancel the token (so still a terminate method), while requiring tasks to be rewritten to check the token periodically.

On top of this, things like the source table, routing table, seqno cache, which spawn timers should also cancel the timers when they get dropped.

When the PeerManagerInner actually gets dropped, it should likely also cancel all peers it knows about.

@LeeSmet LeeSmet added the type_feature New feature or request label Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type_feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant