-
Notifications
You must be signed in to change notification settings - Fork 2.2k
skip setup signal notifier for detached container #4661
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ import ( | |
| "github.com/opencontainers/runc/libcontainer" | ||
| "github.com/opencontainers/runc/libcontainer/configs" | ||
| "github.com/opencontainers/runc/libcontainer/specconv" | ||
| "github.com/opencontainers/runc/libcontainer/system" | ||
| "github.com/opencontainers/runc/libcontainer/system/kernelversion" | ||
| "github.com/opencontainers/runc/libcontainer/utils" | ||
| ) | ||
|
|
@@ -218,14 +219,16 @@ type runner struct { | |
| subCgroupPaths map[string]string | ||
| } | ||
|
|
||
| func (r *runner) run(config *specs.Process) (int, error) { | ||
| var err error | ||
| func (r *runner) run(config *specs.Process) (_ int, retErr error) { | ||
| detach := r.detach || (r.action == CT_ACT_CREATE) | ||
| defer func() { | ||
| if err != nil { | ||
| // For a non-detached container, or we get an error, we | ||
| // should destroy the container. | ||
| if !detach || retErr != nil { | ||
rata marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we always want to do this for !detach containers? What if we fail before we start the process? Is this handled fine by r.destroy()? Or does this kill something else too, and we should do it here? I don't know, maybe we want to just do it later in the other defer? I'd like to understand why one or the other, though. But that is what we were doing before, though, the destroy was not called for this part of the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, I just move this destroy from the last to defer.
I think without !detach || , it behaves the same as before — it would call destroy whenever an error occurred, regardless of whether it was a detach operation or not. Please let me know if I missed anything. |
||
| r.destroy() | ||
| } | ||
| }() | ||
| if err = r.checkTerminal(config); err != nil { | ||
| if err := r.checkTerminal(config); err != nil { | ||
| return -1, err | ||
| } | ||
| process, err := newProcess(config) | ||
|
|
@@ -250,11 +253,19 @@ func (r *runner) run(config *specs.Process) (int, error) { | |
| } | ||
| process.ExtraFiles = append(process.ExtraFiles, os.NewFile(uintptr(i), "PreserveFD:"+strconv.Itoa(i))) | ||
| } | ||
| detach := r.detach || (r.action == CT_ACT_CREATE) | ||
| // Setting up IO is a two stage process. We need to modify process to deal | ||
| // with detaching containers, and then we get a tty after the container has | ||
| // started. | ||
| handlerCh := newSignalHandler(r.enableSubreaper, r.notifySocket) | ||
| if r.enableSubreaper { | ||
| // set us as the subreaper before registering the signal handler for the container | ||
rata marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err := system.SetSubreaper(1); err != nil { | ||
rata marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| logrus.Warn(err) | ||
| } | ||
| } | ||
| var handlerCh chan *signalHandler | ||
| if !detach { | ||
| handlerCh = newSignalHandler() | ||
| } | ||
| tty, err := setupIO(process, r.container, config.Terminal, detach, r.consoleSocket) | ||
| if err != nil { | ||
| return -1, err | ||
|
|
@@ -282,29 +293,32 @@ func (r *runner) run(config *specs.Process) (int, error) { | |
| if err != nil { | ||
| return -1, err | ||
| } | ||
| defer func() { | ||
| // We should terminate the process once we got an error. | ||
| if retErr != nil { | ||
| r.terminate(process) | ||
|
Comment on lines
+296
to
+299
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is duplicated now. The function deferred previously will also do the exact same thing. Is this on purpose? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Therefore, was this also unnecessary in the past? I suggest we keep it, as there may have been scenarios we haven't taken into account. |
||
| } | ||
| }() | ||
| if err = tty.waitConsole(); err != nil { | ||
| r.terminate(process) | ||
| return -1, err | ||
| } | ||
| tty.ClosePostStart() | ||
| if r.pidFile != "" { | ||
| if err = createPidFile(r.pidFile, process); err != nil { | ||
| r.terminate(process) | ||
| return -1, err | ||
| } | ||
| } | ||
| handler := <-handlerCh | ||
| status, err := handler.forward(process, tty, detach) | ||
| if err != nil { | ||
| r.terminate(process) | ||
| if r.notifySocket != nil { | ||
| if err = r.notifySocket.forward(process, detach); err != nil { | ||
| return -1, err | ||
| } | ||
| } | ||
| if detach { | ||
| return 0, nil | ||
| } | ||
| if err == nil { | ||
| r.destroy() | ||
| } | ||
| return status, err | ||
| // For non-detached container, we should forward signals to the container. | ||
| handler := <-handlerCh | ||
| return handler.forward(process, tty) | ||
| } | ||
|
|
||
| func (r *runner) destroy() { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.