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

Ignore error when killing, if error is 'process does not exist' #1339

Merged
merged 1 commit into from
Nov 14, 2022

Conversation

YJDoc2
Copy link
Collaborator

@YJDoc2 YJDoc2 commented Nov 10, 2022

Currently when killing a container, if the container process does not exist (already deleted) or when killing all processes in the container, a process exits between we getting its pid and sending the kill signal, kill command will produce error.

However, in this specific case, it is ok that killing failed, as the process to kill does not exist. So we ignore the error.

Note, I'd like the check of error code to be more idiomatic, but not sure how

Comment on lines +60 to +67
let res = signal::kill(pid, signal);

match res {
Err(nix::errno::Errno::ESRCH) => {
/* the process does not exist, which is what we want */
}
_ => res?,
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more idiomatic way of doing this?

Comment on lines +106 to +113
let res = signal::kill(pid, signal);
match res {
Err(nix::errno::Errno::ESRCH) => {
/* the process does not exist, which is what we want */
Ok(())
}
_ => res,
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now thinking, I'm not sure if we need this, as we are freezing the cgroup before getting all pids, so whatever pids we get, the process must exist, as freezing cgroup will suspend all processes in the cgroup

Copy link
Member

@utam0k utam0k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I ask you to add this test case into our integration test?

@YJDoc2
Copy link
Collaborator Author

YJDoc2 commented Nov 14, 2022

May I ask you to add this test case into our integration test?

I'm not sure what you mean by this. If we want to add a new test to validate this, I'm not sure how would I go about doing this, because this is basically a race condition. The problem here was that between we getting list of processes and we sending the kill signal, a process from list exits on its own, making the kill call fail. As we want to kill the process anyways, and it has exited, here we just ignore that specific failure. In my opinion, it would be difficult to consistently recreate this race condition in a test.

Let me know if I'm getting this wrong

@utam0k
Copy link
Member

utam0k commented Nov 14, 2022

May I ask you to add this test case into our integration test?

I'm not sure what you mean by this. If we want to add a new test to validate this, I'm not sure how would I go about doing this, because this is basically a race condition. The problem here was that between we getting list of processes and we sending the kill signal, a process from list exits on its own, making the kill call fail. As we want to kill the process anyways, and it has exited, here we just ignore that specific failure. In my opinion, it would be difficult to consistently recreate this race condition in a test.

Let me know if I'm getting this wrong

You are right!

@utam0k utam0k merged commit a25de6c into youki-dev:main Nov 14, 2022
@YJDoc2 YJDoc2 deleted the kill_ignore_ESRCH branch December 1, 2022 08:57
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.

2 participants