Skip to content

runcexecutor: change how the runc executor kills runc processes - #6779

Merged
tonistiigi merged 1 commit into
moby:masterfrom
jsternberg:runc-kill-delay
May 23, 2026
Merged

tonistiigi merged 1 commit into
moby:masterfrom
jsternberg:runc-kill-delay

Conversation

@jsternberg

Copy link
Copy Markdown
Collaborator

Change how the runc executor kills runc processes by removing the
previous warning message that occurred every 50 milliseconds with a bit
more precision in how it sends the warning.

The previous version could potentially successfully kill the runc
process and then the runc process could take some time to exit. It would
spam the logs every 50 milliseconds until the process exited and would
attempt to rekill a container that was already marked as killed.

This change makes it so we detect a successful kill. If we detect a
successful kill, we then wait for the process while writing a warning to
the log that the process is taking a long time to end. We print one
message 50 milliseconds after the kill and then an additional one with
the exact time it took to exit after the exit succeeds.

If the kill is not successful, we stay in the same loop as previously
existed.

Related to #4483.

@AkihiroSuda

Copy link
Copy Markdown
Member

How did you test this PR?

@jsternberg

Copy link
Copy Markdown
Collaborator Author

@AkihiroSuda beyond just pushing to run CI I haven't done any special testing. I'll change this to draft and try to mess with the runc binary a little bit just to verify the messages get printed as I expect them to.

@jsternberg
jsternberg marked this pull request as draft May 18, 2026 16:59
Change how the runc executor kills runc processes by removing the
previous warning message that occurred every 50 milliseconds with a bit
more precision in how it sends the warning.

The previous version could potentially successfully kill the runc
process and then the runc process could take some time to exit. It would
spam the logs every 50 milliseconds until the process exited and would
attempt to rekill a container that was already marked as killed.

This change makes it so we detect a successful kill. If we detect a
successful kill, we then wait for the process while writing a warning to
the log that the process is taking a long time to end. We print one
message 50 milliseconds after the kill and then an additional one with
the exact time it took to exit after the exit succeeds.

If the kill is not successful, we stay in the same loop as previously
existed.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
@jsternberg

Copy link
Copy Markdown
Collaborator Author

@AkihiroSuda I added a time.Sleep(time.Second) to runc with this patch.

diff --git a/run.go b/run.go
index b03b8129..7a54cfef 100644
--- a/run.go
+++ b/run.go
@@ -3,6 +3,7 @@ package main
 import (
 	"fmt"
 	"os"
+	"time"
 
 	"github.com/urfave/cli"
 )
@@ -74,6 +75,7 @@ command(s) that get executed on start, edit the args parameter of the spec. See
 			return err
 		}
 		status, err := startContainer(context, CT_ACT_RUN, nil)
+		time.Sleep(time.Second)
 		if err == nil {
 			// exit with the container's exit status so any external supervisor is
 			// notified of the exit with the correct exit status.

I then used that version of runc and created a buildkit container. I created a dockerfile that just does this:

FROM alpine
RUN echo hi; sleep 60; false

I ran it against this change and pushed ctrl+c during the build. I get this output.

time="2026-05-19T19:51:49Z" level=debug msg="> creating qrf9apt2p8hbcr0k58yzywob6 [/bin/sh -c echo hi; sleep 60; false]" span="[2/2] RUN echo hi; sleep 60; false" spanID=c8c460e566391c8a trac
eID=63e57827d412d34c2c84cd312a23b225
time="2026-05-19T19:51:52Z" level=debug msg="sending sigkill to process in container qrf9apt2p8hbcr0k58yzywob6" span="[2/2] RUN echo hi; sleep 60; false" spanID=c8c460e566391c8a traceID=63e57
827d412d34c2c84cd312a23b225
time="2026-05-19T19:51:52Z" level=debug msg="session finished: <nil>" spanID=c3515173219313e9 traceID=63e57827d412d34c2c84cd312a23b225
time="2026-05-19T19:51:52Z" level=warning msg="container id qrf9apt2p8hbcr0k58yzywob6 is taking a long time to exit after kill" span="[2/2] RUN echo hi; sleep 60; false" spanID=c8c460e566391c
8a traceID=63e57827d412d34c2c84cd312a23b225
time="2026-05-19T19:51:53Z" level=warning msg="container id qrf9apt2p8hbcr0k58yzywob6 took 1.008263651s to exit" span="[2/2] RUN echo hi; sleep 60; false" spanID=c8c460e566391c8a traceID=63e5
7827d412d34c2c84cd312a23b225
time="2026-05-19T19:51:53Z" level=error msg="/moby.buildkit.v1.Control/Solve returned error: rpc error: code = Canceled desc = context canceled" spanID=4b6fb9e21a021af9 traceID=63e57827d412d3
4c2c84cd312a23b225

This is the output I would expect from the change. Without this change, here's the output that I get with the same runc change.

time="2026-05-19T20:08:14Z" level=debug msg="> creating z03d4vro36oqdojkti9j1u8om [/bin/sh -c echo hi; sleep 60; false]" span="[2/2] RUN echo hi; sleep 60; false" spanID=0f0e1329e5934704 traceID=a2c6200dcdbdbaf2d9c407aaa59be1c5
time="2026-05-19T20:08:15Z" level=debug msg="sending sigkill to process in container z03d4vro36oqdojkti9j1u8om" span="[2/2] RUN echo hi; sleep 60; false" spanID=0f0e1329e5934704 traceID=a2c6200dcdbdbaf2d9c407aaa59be1c5
time="2026-05-19T20:08:15Z" level=debug msg="session finished: <nil>" spanID=ea316a4d9565c270 traceID=a2c6200dcdbdbaf2d9c407aaa59be1c5
time="2026-05-19T20:08:15Z" level=debug msg="sending sigkill to process in container z03d4vro36oqdojkti9j1u8om" span="[2/2] RUN echo hi; sleep 60; false" spanID=0f0e1329e5934704 traceID=a2c6200dcdbdbaf2d9c407aaa59be1c5
time="2026-05-19T20:08:15Z" level=error msg="failed to kill process in container id z03d4vro36oqdojkti9j1u8om: buildkit-runc did not terminate successfully: exit status 1: container not running\n" span="[2/2] RUN echo hi; sleep 60; false" spanID=0f0e1329e5934704 traceID=a2c6200dcdbdbaf2d9c407aaa59be1c5
time="2026-05-19T20:08:15Z" level=debug msg="sending sigkill to process in container z03d4vro36oqdojkti9j1u8om" span="[2/2] RUN echo hi; sleep 60; false" spanID=0f0e1329e5934704 traceID=a2c6200dcdbdbaf2d9c407aaa59be1c5
time="2026-05-19T20:08:15Z" level=error msg="failed to kill process in container id z03d4vro36oqdojkti9j1u8om: buildkit-runc did not terminate successfully: exit status 1: container not running\n" span="[2/2] RUN echo hi; sleep 60; false" spanID=0f0e1329e5934704 traceID=a2c6200dcdbdbaf2d9c407aaa59be1c5
time="2026-05-19T20:08:15Z" level=debug msg="sending sigkill to process in container z03d4vro36oqdojkti9j1u8om" span="[2/2] RUN echo hi; sleep 60; false" spanID=0f0e1329e5934704 traceID=a2c6200dcdbdbaf2d9c407aaa59be1c5
time="2026-05-19T20:08:15Z" level=error msg="failed to kill process in container id z03d4vro36oqdojkti9j1u8om: buildkit-runc did not terminate successfully: exit status 1: container not running\n" span="[2/2] RUN echo hi; sleep 60; false" spanID=0f0e1329e5934704 traceID=a2c6200dcdbdbaf2d9c407aaa59be1c5

There's a lot more of that same message so I do think that this message is likely just caused by some logging code for runc that's a bit too noisy.

@jsternberg
jsternberg marked this pull request as ready for review May 19, 2026 20:09
@tonistiigi
tonistiigi merged commit d6b444d into moby:master May 23, 2026
214 of 215 checks passed
@jsternberg
jsternberg deleted the runc-kill-delay branch May 23, 2026 04:21
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.

3 participants