-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Plugins should be killed on exit #234
Comments
Yes, they are killed on exit. Plugins are hold in a https://github.com/shadowsocks/shadowsocks-rust/blob/master/src/plugin/mod.rs#L49 |
Hmm on Android they're not being terminated correctly. Maybe need some other mechanisms like signaling? @madeye |
Yeah, we send Let me double check locally. |
|
I send It looks we need to handle |
Steps to reproduce: sslocal --server-addr 127.0.0.1:6001 --local-addr 127.0.0.1:1080 -k password -m rc4-md5 --plugin v2ray-plugin --plugin-opts "host=example.com"
killall sslocal
ps aux | grep v2ray |
It works correctly in macOS (launchd) and Debian 9 (with systemd). |
I tested on Ubuntu 18.04... It's interesting that we see different behavior. |
And the output of shadowsocks-rust
|
Ah, unfortunately, yes. v2ray is not killed! I can reproduce that. |
It should be fixed by this commit. |
Yeah, I can also reproduce it in Ubuntu 18.04. I should release a new version to fix this bug. |
According to doc, |
That's because |
Yeah that does not seem to be cross platform... For now, we can just use a Unix-only block to ask the process to terminate first and then kill it after a timeout maybe. Something like this: https://github.com/shadowsocks/shadowsocks-android/blob/7fdcee61216ff35427bf0719d3c542b557ea1f79/core/src/main/java/com/github/shadowsocks/bg/GuardedProcessPool.kt#L93-L108
Related: rust-lang/rust#41822 |
This is not an easy task to implement "kill and wait then timeout". Because we are running this in a |
There is a simple solution, pseudocode: for plugin in &mut self.plugins {
plugin.terminate();
}
// Blocks process for 500ms
sleep(500ms);
// Kills all of them
for plugin in &mut self.plugins {
plugin.kill();
} |
I guess we only terminate plugins on exit/being terminated so blocking the entire process/thread is probably acceptable. |
Hmm 67de124 waits 500ms unconditionally but clean up might be much faster... Maybe consider some sort of |
Verified locally on Android. The latest fix works well. |
It is unwise to do such a lot of things in |
How about |
Nope. Runtime is also dropping. |
Runtime should be dropped after everything else right...? We can also release stuff in Runtime's drop handler I guess? |
Nope. I tried. Spawning into a panicking Runtime will cause another panic. |
Hmm if this is really that difficult we can try to clean up the child processes from JVM. A 500ms delay seems undesirable to me. |
I think we'd better handle this in shadowsocks-rust, as it's not the problem only on Android. Given we already use unsafe code to send |
Yes, it should be a problem to be handled in shadowsocks-rust. It seems that for plugin in &self.plugins {
let mut status: libc::c_int = 0;
libc::waitpid(plugin.id(), &mut status, 0);
} Another option is to use A very tricky solution is to use |
How about this. |
I see the current solution is a busy spin -- |
|
Well the code I quoted simply spawns (or actually reuse) another thread that runs |
That is probably slower. I tested on my laptop and |
Yeah I guess I will take this fix for now. Thanks for bearing with me! 🤣 |
Maybe the way to do it is instead to catch |
If any |
Well we can always use another macro for panic but you are right... |
Some related discussions about Asynchronous Destruction. |
I think scoped concurrency might help as that way we can destruct objects with blocking the runtime before Runtime destructs itself. |
https://stackoverflow.com/a/30540177/2245107
The text was updated successfully, but these errors were encountered: