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

Gracefully shut down tarpc #473

Closed
massimo79m opened this issue Sep 10, 2024 · 2 comments
Closed

Gracefully shut down tarpc #473

massimo79m opened this issue Sep 10, 2024 · 2 comments

Comments

@massimo79m
Copy link

I'm writing a daemon with two threads: a tarpc that gets the client requests, and a "worker".
When i terminate (TERM signal, not KILL), i need that the tarpc shuts down gracefully, simply not accepting further connections but serving the active requests.
Is there a way?
i've read #307 but i could not find a way.

@tikue
Copy link
Collaborator

tikue commented Sep 10, 2024

Hi, thanks for the question! It should be possible. Can you share your code? Do you have a task that accepts new channels, and then you have a separate task executing each channel? If so, basically you'd just want the channel-accepting task to be abortable (might be able to just wrap it in an abortable future), and then there'd be a signal handler that aborts it. I haven't used signal handlers in rust. The CLI book has some instructions for setting up a thread that handles signals: https://rust-cli.github.io/book/in-depth/signals.html

@massimo79m
Copy link
Author

massimo79m commented Sep 12, 2024

Thank you for the comment!
sadly i can't share the code, because actually i'm writing the business logic library that will be used by this daemon, not the daemon itself, i will write it eventually.

Actually i used the term "worker" in a different way: the "worker thread" will do some math, file, net and db work, constantly and independently, and another thread (the one with tarpc) that listens for the client requests (simple CLI + tarpc applications on client PCs), and this thread will read the requests from tarpc and it will set some variables used by the "worker thread".
the "task" of the tarpc will be very fast, i will not need to spawn a thread for a request.

I used "abortable" and works perfectly.
thank you very much.

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