nerdctl icon indicating copy to clipboard operation
nerdctl copied to clipboard

fix: shutdown logger after container process exits

Open mharwani opened this issue 2 years ago • 8 comments

Addresses #2313

Container task is not deleted after it exits, leaving the runtime shim and logger open throughout the lifecycle of a container. This can be a problem when there is unprocessed stdout data after a container task finishes and the logger is blocked forever waiting for a newline or EOF.

This PR fixes the issue by piping container output instead of reading directly from stdout and stderr file descriptors. Closing the io pipes upon task exit allows the logger to shutdown gracefully and process leftover data without a newline .

mharwani avatar Jun 29 '23 09:06 mharwani

Hi @mharwani, as mentioned here closing task io io.Close() after task exiting should close FIFOs => send EOF to stdio => logger will receive EOF

fahedouch avatar Jul 10 '23 22:07 fahedouch

Hi @mharwani, as mentioned here closing task io io.Close() after task exiting should close FIFOs => send EOF to stdio => logger will receive EOF

Hi @fahedouch, I tried closing the task IO upon container exit with task.IO().Close(), but it did not fix the issue. The scanner did not receive EOF. I posted my thoughts here:

From what I understand, when a task is running in detached mode it uses logURI as the task IO, which doesn't have any FIFOs open and does nothing on close.

mharwani avatar Jul 11 '23 14:07 mharwani

It looks like the environment setup is failing for some of the checks because curl cannot reach the endpoint https://raw.githubusercontent.com/AkihiroSuda/containerized-systemd/v0.1.1/docker-entrypoint.sh: SSL: no alternative certificate subject name matches target host name 'raw.githubusercontent.com'

Any ideas?

mharwani avatar Jul 19 '23 15:07 mharwani

CI is now green for Linux. Please try rebasing to make Windows CI green

AkihiroSuda avatar Jul 21 '23 15:07 AkihiroSuda

Windows tests are failing

=== NAME  TestLogs
    container_logs_test.go:42: assertion failed: 
        Command:  C:\Windows\system32\config\systemprofile\go\bin\nerdctl.exe --namespace=nerdctl-test logs --since 10s nerdctl-testlogs
        ExitCode: 0
        Stdout:   
        Stderr:   
        Failures:
        Expected stdout to contain "foo\nbar"
=== CONT  TestLogsWithoutNewlineOrEOF
--- FAIL: TestLogs (4.60s)
=== NAME  TestLogsAfterRestartingContainer

https://cirrus-ci.com/task/4610614887186432?logs=build#L843

AkihiroSuda avatar Jul 31 '23 06:07 AkihiroSuda

@mharwani PTAL

fahedouch avatar Aug 25 '23 09:08 fahedouch

ping @mharwani

AkihiroSuda avatar Oct 08 '23 22:10 AkihiroSuda

Hey @mharwani

Would you still be interested in carrying this PR through? If so, could you rebase (a lot has changed) and see about @fahedouch comments?

apostasie avatar Aug 08 '24 17:08 apostasie