fix: shutdown logger after container process exits
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 .
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 @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.
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?
CI is now green for Linux. Please try rebasing to make Windows CI green
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
@mharwani PTAL
ping @mharwani
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?