Skip to content

docker daemon ContainerStop: dont wait forever if docker kill fails#41580

Closed
sparrc wants to merge 1 commit into
moby:masterfrom
sparrc:stop-kill-lock-fix
Closed

docker daemon ContainerStop: dont wait forever if docker kill fails#41580
sparrc wants to merge 1 commit into
moby:masterfrom
sparrc:stop-kill-lock-fix

Conversation

@sparrc

@sparrc sparrc commented Oct 23, 2020

Copy link
Copy Markdown

fixed #41579

- What I did

remove waiting without a timeout when docker kill fails within docker stop

before change:

cli:

% docker stop # hangs forever
Oct 23 04:17:23 ip-10-0-0-176.us-west-2.compute.internal dockerd[29371]: time="2020-10-23T04:17:23.883792164Z" level=info msg="Container e0d10e9ca9d06815a903de8bab96c98b7b7d2435f6afc41bbe54e188f112564c failed to exit within 10 seconds of signal 15 - using the force"

after change:
cli:

% docker stop kt
Error response from daemon: cannot stop container: kt: Container failed to stop after sending SIGKILL

docker logs:

Oct 23 04:37:40 ip-10-0-0-11.us-west-2.compute.internal dockerd[23274]: time="2020-10-23T04:37:40.420268417Z" level=info msg="Container 78d066d275b7f28ccd2d71b386aa5a9b119424bc89472bc595b340fb69a42fea failed to exit within 10 seconds of signal 15 - using the force"
Oct 23 04:37:40 ip-10-0-0-11.us-west-2.compute.internal dockerd[23274]: time="2020-10-23T04:37:40.420308880Z" level=error msg="Container 78d066d275b7f28ccd2d71b386aa5a9b119424bc89472bc595b340fb69a42fea failed to SIGKILL container: Error killing container"
Oct 23 04:37:50 ip-10-0-0-11.us-west-2.compute.internal dockerd[23274]: time="2020-10-23T04:37:50.420504579Z" level=error msg="Handler for POST /v1.40/containers/kt/stop returned error: cannot stop container: kt: Container failed to stop after sending SIGKILL"

- Description for the changelog

Fix hanging docker stop if SIGTERM and SIGKILL both fail

- A picture of a cute animal (not mandatory but encouraged)

@sparrc
sparrc force-pushed the stop-kill-lock-fix branch from e134d6d to 3bedf15 Compare October 23, 2020 04:56
@thaJeztah

Copy link
Copy Markdown
Member

@cpuguy83 @tonistiigi ptal

@sparrc

sparrc commented Oct 23, 2020

Copy link
Copy Markdown
Author

jenkins failures look like only s390x integration tests related to pinging so I dont think they're related to this change.

@sparrc
sparrc force-pushed the stop-kill-lock-fix branch from b03359c to 1e31af2 Compare October 23, 2020 16:53
@sparrc

sparrc commented Oct 23, 2020

Copy link
Copy Markdown
Author

Update: I pushed a second commit to this because I found that there is also a wait without timeout within the Kill function. It seemed closely-related enough to be on the same PR to me, but I can also break it into a separate PR if you would prefer.

Comment thread daemon/stop.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.

I wonder if this wait is even needed. What's the reasoning behind waiting indefinitely if Kill returns an error?
It seems this code assumes that there will be an containerpkg.WaitConditionNotRunning even if Kill fails, but that doesn't seem to be true in all cases (if at all), which is why this function waits for ever, as described in #41579

I think we should just return the error here
Thoughts?

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.

I think it's worth waiting.

Also, FWIW, I think the potential for deadlock here is small.
There were some bugs related to error handling from runc as well as event processing from containerd that would trigger a problem here, but those are cleaned up.

That said, totally fine to not wait for ever.
The assumption to wait forever has likely been passed down from old versions where docker directly managed the container process, where as now that has containerd in the middle.

@sparrc sparrc Oct 23, 2020

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm also not sure about the usefulness of waiting, @cpuguy83 would you be opposed to at least reducing the timeout to 2 seconds like the code does in a few other places?

The downside of waiting at all is that the containerStop function can already take quite a lot longer to return than the seconds input argument, and waiting here makes that worse.

Comment thread daemon/stop.go Outdated

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.

This error is not really accurate, because SIGKILL really means that the kernel is terminating the process.
What is happening is dockerd is not receiving an exit event, for whatever reason, from containerd, maybe we should reflect that in the error message.

Also note, error messages should start lowercase for code style. Log messages with capital is fine.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

okay, how about "tried to kill container, but did not receive an exit event" ?

Comment thread daemon/stop.go Outdated
Comment thread daemon/stop.go Outdated
docker daemon: dont wait without timeout in docker kill

fixes moby#41579

Signed-off-by: Cam <[email protected]>
@sparrc
sparrc force-pushed the stop-kill-lock-fix branch from 1e31af2 to 216be72 Compare October 23, 2020 21:14
@sparrc

sparrc commented Oct 23, 2020

Copy link
Copy Markdown
Author

changes pushed addressing some comments, others still pending feedback

@sparrc

sparrc commented Oct 24, 2020

Copy link
Copy Markdown
Author

closing this in favor of #41586, as I found a few other issues in stop container that I thought were worth addressing with a larger refactor.

@sparrc sparrc closed this Oct 24, 2020
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.

docker stop hangs forever if it falls back to docker kill and docker kill fails

4 participants