Skip to content

Fix restart docker daemon with paused containers#13304

Merged
cpuguy83 merged 1 commit into
moby:masterfrom
coolljt0725:restart_daemon_with_paused_containers
Aug 26, 2015
Merged

Fix restart docker daemon with paused containers#13304
cpuguy83 merged 1 commit into
moby:masterfrom
coolljt0725:restart_daemon_with_paused_containers

Conversation

@coolljt0725

Copy link
Copy Markdown
Contributor

Signed-off-by: Lei Jitang [email protected]

I think this is better fix than #12802 .
Restarting docker daemon with paused containers really caused a big problem,
the paused containers will can't be start on docker daemon restart, and if the
paused containers happened to have a restart policy restart=always, the daemon will hang.
So, I think we should prevent these from happening.
This fix is to send 15 to container and then unpause it, this is just what
the kernel designed for. If we want terminate a process in freezer cgroup,
we should send terminate signal to this process and then unfreeze it, and then this process will
terminate. In this way, it will not case unsafe problem.
ping @LK4D4 @aluzzardi @tiborvass @jfrazelle @cpuguy83
cc @lexandro

But if we just want to keep it work like it does today, pls feel free to close :)

@jessfraz

Copy link
Copy Markdown
Contributor

I dont think you can SIGTERM a paused container? but someone correct me if I am wrong

@cpuguy83

Copy link
Copy Markdown
Member

Correct, it won't do anything since it's been frozen and as such can't respond to signals.
From what I understand you can SIGKILL then unfreeze and the process will be forced to exit immediately and won't have a chance to wreck any havoc.

@coolljt0725

Copy link
Copy Markdown
Contributor Author

@cpuguy83 is right, if you want SIGKILL or SIGTERM to a frozen process, you should send
SIGKILL or SIGTERM to the process and unfreeze it, the process will be forced to exit
immediately

@jessfraz

Copy link
Copy Markdown
Contributor

can we have an integration test to prove that is true.

@coolljt0725

Copy link
Copy Markdown
Contributor Author

@jfrazelle Had add a integration test

@thaJeztah

Copy link
Copy Markdown
Member

@coolljt0725 GitHub says it needs a rebase.

@coolljt0725

Copy link
Copy Markdown
Contributor Author

@thaJeztah yeah, thanks

@coolljt0725
coolljt0725 force-pushed the restart_daemon_with_paused_containers branch 2 times, most recently from e3d25b1 to 74aee6e Compare May 25, 2015 13:08
@coolljt0725

Copy link
Copy Markdown
Contributor Author

since #12400 is merged, if the design of this is ok, I'll rebase this. ping @cpuguy83 @LK4D4 @jfrazelle @calavera @thaJeztah

@coolljt0725

Copy link
Copy Markdown
Contributor Author

Hi all, if the design is ok, I'll rebase this

@thaJeztah

Copy link
Copy Markdown
Member

ping @cpuguy83 @calavera @LK4D4 PTAL

@thaJeztah

Copy link
Copy Markdown
Member

Also, @coolljt0725 does this solve #12797?

@LK4D4

LK4D4 commented Jun 8, 2015

Copy link
Copy Markdown
Contributor

design looks ok for me

@duglin

duglin commented Jun 9, 2015

Copy link
Copy Markdown
Contributor

Should we try to fix this upon daemon startup instead? What if the daemon crashes w/o daemon.Shutdown() func having a chance to be called. I'm assuming we'll run into the original issue, right?

@coolljt0725

Copy link
Copy Markdown
Contributor Author

@duglin I think fix this on docker daemon shutdown is also to do some cleanup of containers to avoid orphaned virt interfaces and unmounted rootfs...

@coolljt0725
coolljt0725 force-pushed the restart_daemon_with_paused_containers branch from 74aee6e to 86b39c6 Compare June 9, 2015 12:29
@coolljt0725

Copy link
Copy Markdown
Contributor Author

rebased , ping @LK4D4 @cpuguy83 @jfrazelle @duglin @calavera

@duglin

duglin commented Jun 9, 2015

Copy link
Copy Markdown
Contributor

@coolljt0725 yes but my point is that I don't think we can count on that code always being run. What if someone just pulls the plug on the machine and it dies? Don't we need to do this logic upon daemon startup otherwise things will still be in a bad state?

@coolljt0725

Copy link
Copy Markdown
Contributor Author

@duglin I understand you point , I think this is a common problem not only for docker, other software have the same problem, abnormal shutdown of software will with some information missing and hard to recover or cleanup on next startup.
I think to do this logic upon daemon startup need some journal file, with a journal file we can know if the daemon is shutdown normally and we can do some recover base on the journal file.
This PR is to make normal shutdown of daemon cleanup what has created.

@duglin

duglin commented Jun 9, 2015

Copy link
Copy Markdown
Contributor

@coolljt0725 I haven't had a chance to look into why its hanging, has the investigation been done? Do we know what the fix is to if this cleanup func isn't run? In other words, what can the user do to get out of this bad state?

@coolljt0725

Copy link
Copy Markdown
Contributor Author

@duglin I have investigated this. The hang will only happened when use native.cgroupdriver=cgroupfs, this happened because daemon shutdown leave the paused container cgroup still exitst with freezer.state=FROZEN, so on daemon next startup, when go to https://github.com/docker/libcontainer/blob/master/process_linux.go#L196 the process of the container will join this FROZEN cgroup and become paused, so it hangs.
for native.cgroupdriver=systemd it will return an error [8] System error: Unit docker-xxxxx.scope already exists.

@duglin

duglin commented Jun 10, 2015

Copy link
Copy Markdown
Contributor

@coolljt0725 is there any way to kill the frozen process? (w/o actually rebooting the machine)

@coolljt0725

Copy link
Copy Markdown
Contributor Author

@duglin Sorry for the delay. I think the way to kill the frozen process is to send a SIGTERM or SIGKILL to the process and then remove it from the frozen cgroup or thaw the frozen cgroup

@duglin

duglin commented Jun 13, 2015

Copy link
Copy Markdown
Contributor

@coolljt0725 is this something we can do for those processes during daemon startup to avoid a hang?

Comment thread daemon/daemon.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

os.SIGKILL

@tiborvass

Copy link
Copy Markdown
Contributor

Ping @coolljt0725

@coolljt0725

Copy link
Copy Markdown
Contributor Author

@tiborvass I don't understand your comment above. Do you mean we should add a empty SignalMap in signal_windows.go?
and we get the signal by sig, ok := signal.SignalMap["TERM"] ?

@coolljt0725

Copy link
Copy Markdown
Contributor Author

ping @tiborvass

@jessfraz

Copy link
Copy Markdown
Contributor

so sorry needs a rebase

@coolljt0725
coolljt0725 force-pushed the restart_daemon_with_paused_containers branch 3 times, most recently from ec485a7 to 387310d Compare August 12, 2015 02:53
@coolljt0725

Copy link
Copy Markdown
Contributor Author

@jfrazelle @tiborvass rebased

@jessfraz

Copy link
Copy Markdown
Contributor

so so sorry needs another rebase

@coolljt0725
coolljt0725 force-pushed the restart_daemon_with_paused_containers branch from 387310d to abd03d5 Compare August 24, 2015 03:42
@coolljt0725

Copy link
Copy Markdown
Contributor Author

@jfrazelle @tiborvass rebased

Comment thread daemon/daemon.go

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We probably need to handle this case now being that Windows + Docker is a thing now,

@coolljt0725
coolljt0725 force-pushed the restart_daemon_with_paused_containers branch from abd03d5 to 9a9724a Compare August 25, 2015 01:38
@coolljt0725

Copy link
Copy Markdown
Contributor Author

@jfrazelle @cpuguy83 rebased

@calavera

Copy link
Copy Markdown
Contributor

code LGTM

@cpuguy83

Copy link
Copy Markdown
Member

LGTM, tested locally.

We should probably open a separate issue to discuss handling of paused containers when someone calls stop instead of raising a conflict.

cpuguy83 added a commit that referenced this pull request Aug 26, 2015
…_containers

Fix restart docker daemon with paused containers
@cpuguy83
cpuguy83 merged commit 2cec06f into moby:master Aug 26, 2015
@coolljt0725
coolljt0725 deleted the restart_daemon_with_paused_containers branch August 16, 2016 09:34
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.