-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
new lint: zombie_processes
#11476
new lint: zombie_processes
#11476
Conversation
r? @Centri3 (rustbot has picked a reviewer for you, use r? to override) |
☔ The latest upstream changes (presumably #11413) made this pull request unmergeable. Please resolve the merge conflicts. |
Out of curiosity, does aborting the program also finally release these "zombies" in any way? If so, I think we could check for an unconditional I ask because I was creating a modloader for a game, it'd be loaded then reopen the program with a different entry point before aborting the current program (to run our own code after the loader finishes loading DLLs, or something. No idea why I didn't use function hooking, probably wanted to feel clever ^^). Not really the greatest example, but if the parent process closing allows these zombies to terminate properly, I think it makes sense to check for this. Regardless though, this is a nice lint and I'll review it soon. |
On waitpid's man page there's this note:
So yes, I guess that releases them :) Experiment detailsmain.rs: use std::process::Command;
fn main() {
for _ in 0..5 {
let _ = Command::new("echo").spawn().unwrap(); // <- no wait()
}
println!("Zombies spawned. Press enter to release them");
std::io::stdin().read_line(&mut String::new()).unwrap();
} This doesn't have an explicit exit() call, but this is all at the end of a main function and I think that'd have the same effect. $ rustc main.rs
$ ./main
Zombies spawned. Press enter to release them
# at this point, run `ps aux` in another session and look for 5 `[echo] <defunct>` entries (zombies).
#
# <enter>
#
# now that the process has exited, run `ps aux` again and see that there are no <defunct> entries
(This seems kinda specific to linux, idk if this is needed at all on Windows...)
By this I assume you mean that we shouldn't lint if there is one of these after spawning the process. |
TIL :) Platform-specific lints are fine. For example, Catching a panic is only possible on We could probably extend this to anything that is unconditionally |
Yeah I agree catching panics really shouldnt be done for error handling à la try-catch, but panics are also per thread, so you can panic on one thread and the others (the rest of the program) will live on, and I would say a large number of rust programs involve threads in some way. Another question re. the proposed behavior: would this look at just the next statement after the spawn or how far are we willing to lookahead for an exit? All the way to the end of the enclosing block?
Also to me this makes it sound like that's a rare thing to have but it's the default value ^^, so you have to manually set panic=abort to get it to not unwind
Not sure on this, since expressions like |
Yeah I was wrong, always forget Also forgot Couple thoughts on the behavior:
Stuff like loop expressions should ofc be considered infinitely looping. I think this doesn't have to extend to |
eebbd7a
to
d902ef5
Compare
☔ The latest upstream changes (presumably #11556) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(meow meow), long wait sorry - Looks good overall
Had to rebase because the PR was getting too far behind. The last commit should contain the changes for (most of) the review comments. Also had to split the test up into two files since some of them have suggestions now |
☔ The latest upstream changes (presumably #12306) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks good to me. I would like more tests to ensure that this doesn't result in several FPs, they might require some additional logic in the lint implementation :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The update looks good. One comment and then it should be good to go =^.^=
The next review should also be a bit quicker again. Sorry for the delay.
☔ The latest upstream changes (presumably #12107) made this pull request unmergeable. Please resolve the merge conflicts. |
Sorry for the wait, am a bit busy again, I'll try to get to the rest of this in 2-3 weeks @rustbot author |
Hey @y21 this is another careful ping. Could you look at the last comment? The changes should be simple IIRC |
After having thought about this more for a while, I'm not sure if some of the logic in here is really necessary/worth the complexity. For example, checking if the The logic implies that you It could work if the spawned process finishes quickly enough, but I'd even go as far as saying that it probably should warn on that, exactly because it isn't waiting on the subprocess and the current process might exit prematurely depending on how long it takes. (Then the problem doesn't really have to do with zombie processes anymore, but it would still encourage adding a |
This sounds reasonable to me, feel free to remove that part. If this really comes up as a comment, we can always add it as a limitation to the lint description. :) |
e3ccab4
to
8c673e4
Compare
☔ The latest upstream changes (presumably #12873) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me :D
I've started the FCP: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/FCP.3A.20New.20lint.20.60zombie_processes.60.20rust-clippy.2311476/near/450804727
You can wait with the rebase until the FCP has concluded.
@xFrednet The FCP thread hasn't gotten comments but 4 upvote reactions and it's been about a month -- do you think we're good? I guess it's also waiting on me to do a final rebase. |
Ahh, I totally forgot about this Pr, yes we can count the FCP as accepted. You can |
Looks good to me! Thank you! Roses are red, |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Closes #10754
Lint description should explain this PR, so I think there's nothing else to say here ^^
changelog: new lint: [
zombie_processes
]