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

Kill monero-wallet-rpc child process when receiving SIGINT, SIGTERM o… #1434

Closed
wants to merge 4 commits into from

Conversation

binarybaron
Copy link
Collaborator

@binarybaron binarybaron commented Aug 30, 2023

…r SIGHUP

When the CLI is terminated via a signal, the child process monero-wallet-rpc is not automatically terminated. This discrepancy arises from the behavior of terminal-initiated interrupts (e.g., STRG-C), which send the termination signal to all processes in the process group, effectively killing the child process.

To address this, we implement a signal handler that explicitly terminates the monero-wallet-rpc child process upon receiving a termination signal for the parent process. This ensures that the child process does not continue running in the background, detached from the parent. Failing to terminate the child process would lock the wallet, preventing future instances of the CLI from starting.

Fixes #835

@binarybaron binarybaron force-pushed the kill-monero-rpc-on-signal-receive branch from b3cea64 to d362a41 Compare August 30, 2023 22:31
@binarybaron binarybaron force-pushed the kill-monero-rpc-on-signal-receive branch 2 times, most recently from 1697f2e to 8418e57 Compare August 30, 2023 22:45
@delta1
Copy link
Collaborator

delta1 commented Aug 31, 2023

seems to break the windows build, is there a cross platform way to do the same?

@binarybaron
Copy link
Collaborator Author

I'll look into it

@binarybaron binarybaron force-pushed the kill-monero-rpc-on-signal-receive branch from 8418e57 to 09ce8ed Compare August 31, 2023 07:59
@binarybaron
Copy link
Collaborator Author

I made it platform specific but we still need to test this on Windows. I'll do it in the next few days

@binarybaron
Copy link
Collaborator Author

binarybaron commented Sep 1, 2023

Our current Tokio version doesn't have support for signals on windows... We'll have to upgrade

@binarybaron binarybaron force-pushed the kill-monero-rpc-on-signal-receive branch from 4c9b84f to 78049a9 Compare September 1, 2023 15:58
…r SIGHUP

When the CLI is terminated via a signal, the child process monero-wallet-rpc is not automatically terminated. This discrepancy arises from the behavior of terminal-initiated interrupts (e.g., STRG-C), which send the termination signal to all processes in the process group, effectively killing the child process.

To address this, we implement a signal handler that explicitly terminates the monero-wallet-rpc child process upon receiving a termination signal for the parent process. This ensures that the child process does not continue running in the background, detached from the parent. Failing to terminate the child process would lock the wallet, preventing future instances of the CLI from starting.
@binarybaron binarybaron force-pushed the kill-monero-rpc-on-signal-receive branch from 78049a9 to 96af3fd Compare September 1, 2023 15:59
@binarybaron binarybaron marked this pull request as draft September 2, 2023 23:19
@binarybaron
Copy link
Collaborator Author

@delta1 do you know why the windows binaries arent getting attached as artifacts?

I only have a windows VM and struggling to compile on my machine.

@delta1
Copy link
Collaborator

delta1 commented Sep 4, 2023

oh right, it’s missing the exe extensions on the upload artifact step. i had a fix for this somewhere, let me try find it or redo it.

@binarybaron
Copy link
Collaborator Author

binarybaron commented Sep 4, 2023

Ok, this does not work on windows due to the tokio version upgrade... Swap terminates with

thread 'main' has overflowed its stack

@binarybaron
Copy link
Collaborator Author

binarybaron commented Sep 4, 2023

Also doesn't work on tokio 1.21.0. @delta1 Do you have an idea what could be causing this? I'm currently looking through the tokio changelog to see if I find anything https://github.com/tokio-rs/tokio/blob/master/tokio/CHANGELOG.md

@delta1
Copy link
Collaborator

delta1 commented Sep 5, 2023

Ok, this does not work on windows due to the tokio version upgrade... Swap terminates with

thread 'main' has overflowed its stack

does this happen immediately or only when it catches the signal?

@binarybaron
Copy link
Collaborator Author

binarybaron commented Sep 5, 2023

Immediately. It's definitely due to the Tokio upgrade. Upgrading Tokio on master without the other changes also caused a crash.

It also crashes on commands like balance where the monero wallet is not initialized. Before crashing the tracing initialization log message is printed which means that it doesn't overflow immediately on startup.

Maybe we really need to increase the stack size but I wonder why.

@binarybaron
Copy link
Collaborator Author

Immediately. It's definitely due to the Tokio upgrade. Upgrading Tokio on master without the other changes also caused a crash.

It also crashes on commands like balance where the monero wallet is not initialized. Before crashing the tracing initialization log message is printed which means that it doesn't overflow immediately on startup.

Maybe we really need to increase the stack size but I wonder why.

Update: This is not related to the tokio upgrade. All debug releases on windows currently panic due to a stackoverflow which means that this PR does not break anything.
However, I'm not sure yet if this PR achieves the desired behaviour on windows. I'll have to look into that.

@binarybaron
Copy link
Collaborator Author

Closing this for now...

@binarybaron binarybaron closed this Nov 9, 2023
@BrandyJSon
Copy link

@binarybaron did you ever find if this could be merged without breaking windows builds. Makes spawning the swap tool programmatically quite annoying to clean up.

@binarybaron
Copy link
Collaborator Author

No I haven't but feel free to open a PR. I'll happily review and merge it if it works on all platforms (or at least doesn't break any platforms)

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.

monero-wallet-rpc stays alive after cli is killed
3 participants