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

feat: interpret all docker states with shutdown #311

Merged
merged 3 commits into from
Feb 8, 2024

Conversation

hansieodendaal
Copy link
Contributor

Description

  • Added code to interpret all docker states with shutdown and act accordingly. This is to prevent Docker from going into undefined states with undefined behaviour.
  • Improved shutdown, in general, to give time for docker containers to be shutdown properly.
  • Improved shutdown when docker is closed manually.

Motivation and Context

All docker states were not interpreted and this caused docker containers to be left in undefined states when exiting.

How Has This Been Tested?

System-level tests on Windows and Ubuntu-WSL

std::process::exit(0);
} else {
std::thread::spawn(|| {
Copy link
Contributor

Choose a reason for hiding this comment

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

You are not waiting on this task, so will it actually end?

Copy link
Contributor Author

@hansieodendaal hansieodendaal Feb 7, 2024

Choose a reason for hiding this comment

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

I tested it, and it ends when the application exits normally, or it does its thing after 60s

std::process::exit(0);
} else {
std::thread::spawn(|| {
std::thread::sleep(std::time::Duration::from_secs(60));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why so long?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As per above, we need ample time for the application to shutdown normally before the failsafe kicks in forcefully.

self.dashboard.take();
ctx.shutdown();
tokio::time::sleep(Duration::from_secs(10)).await;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an event we can wait for instead of this fixed time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, this seems to work fine. I did start a separate branch to get a tokio oneshot channel going as I could not find any events wired into here, but that will take some time to complete.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with Mike. You can get feedback that the docker process has exited, rather than wait for nnn seconds to close the app

Copy link
Contributor

Choose a reason for hiding this comment

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

tbc, I'm ok to merge this behaviour now, but really need to get the proper shutdown behaviour in as a follow up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I expanded the Docker status mapping and now properly handle ContainerState::NotFound during shutdown, which in turn enabled me to remove the sleep-when-exit statements in the launchpad front end.

Copy link
Collaborator

@brianp brianp left a comment

Choose a reason for hiding this comment

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

utAck

@@ -153,9 +153,14 @@ impl Default for Status {

#[derive(Debug, PartialEq, Eq)]
pub enum ContainerState {
Empty,
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the empty state? Would this be the equivalent to the previous NotFound ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Possibly similar to NotFound, but I wouldn't be able to say. No explanation about Empty in https://docs.rs/bollard/latest/bollard/models/enum.ContainerStateStatusEnum.html. I also did not pick it up in the log files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, your questions made me rethink my shutdown proposal, and ContainerState::NotFound should not be removed. I expanded the Docker status mapping and now properly handle ContainerState::NotFound during shutdown. I could also remove the sleep-when-exit statements in the launchpad front end.

When the containers are running fn inspect_container will return some status, but when they are removed, for example during shutdown, it will return an error, which we then map to ContainerState::NotFound.

Added code to interpret all docker states and act accordingly. This is to
prevent Docker going into undefined states with undefined behaviour.
@brianp brianp merged commit 0716ffe into tari-project:main Feb 8, 2024
5 checks passed
@hansieodendaal hansieodendaal deleted the ho_docker_states branch February 8, 2024 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants