Open srhb opened 1 year ago
Do you have to use async, or is this just for illustration?
It's mostly an example. The "real" program is an API served over HTTP, which responds to various commands, updates repos from upstream based on those commands, and spawns (ephemeral) child processes to operate on those repos. SIGCHLD is more or less unavoidable, but the rest could possibly be restructured, though I'm not quite sure how.
I might be wrong, but I don't think there really is a way to work around this, except by avoiding this SIGCHLD business altogether (run the normal std::process::Command
). Or, perhaps by registering a custom transport which would give you more control over IO / syscalls.
You could also try using Tokio's command which as far as I have run into, doesn't work by polluting your main process with signals. Or spawn a subprocess to isolate this mechanism away from the rest of your code. You will find a lot of things don't play well with signals, not just this library. One approach is to set SA_RESTART, or wrap all of your syscalls in a retry for EINTR. https://www.gnu.org/software/libc/manual/html_node/Interrupted-Primitives.html
Warning: If you run the test program, it will pollute your
$TMP
dir. Beware!I wrote a test program to explain my question.
https://github.com/srhb/git2-rs-debug-eintr/blob/main/src/main.rs It can be run with a ssh git repo as its first argument and assumes a private key at ~/.ssh/id_rsa:
The program does two things continuously:
1) continuously clones the repo to a fresh temporary directory 2) runs
true
in a tight loop via async-processThis causes a problem with libssh2 (via git2-rs)
Copy/paste of explanatory comment from my test program: