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

Fix graceful shutdown when intermediate or init process errors or panic #238

Merged
merged 7 commits into from
Aug 28, 2021

Conversation

yihuaf
Copy link
Collaborator

@yihuaf yihuaf commented Aug 27, 2021

Fix #237 Tracking #221

Gracefully shutdown by closing down unused fds in the channel. In this case, when the child process exits, the parent waiting (read_exact) is exit blocking and error out. When fork, the fds in the channel are duplicated, so there are two receivers and two senders. Since we force the channel to become uni-directional, we can safely close the additional fds.

Also in the PR, we should only set host name when entering into a new UTS namespace. One of the integration test doesn't create any new uts namespace, so calling set_hostname is not a good idea.

Now pass one more integration test. The test essentially asks Youki to enter into the wrong type of namespace and see if Youki will error out.

Comment on lines +113 to +121
unistd::close(self.receiver.as_raw_fd())?;

Ok(())
}

pub fn close_sender(&self) -> Result<()> {
unistd::close(self.sender.as_raw_fd())?;

Ok(())
Copy link
Member

Choose a reason for hiding this comment

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

How about this code?

Suggested change
unistd::close(self.receiver.as_raw_fd())?;
Ok(())
}
pub fn close_sender(&self) -> Result<()> {
unistd::close(self.sender.as_raw_fd())?;
Ok(())
unistd::close(self.receiver.as_raw_fd())
}
pub fn close_sender(&self) -> Result<()> {
unistd::close(self.sender.as_raw_fd())

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unistd functions will return a different error type than anyhow result, so we have to use ? for a conversion.

yihuaf and others added 2 commits August 28, 2021 01:35
Co-authored-by: utam0k <k0ma@utam0k.jp>
@yihuaf yihuaf merged commit ff582b7 into containers:main Aug 28, 2021
@yihuaf yihuaf deleted the yihuaf/221 branch August 28, 2021 08:48
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.

Graceful shutdown Youki when forked process returns an error
3 participants