Skip to content

Commit

Permalink
logs.go: fixed logger creation
Browse files Browse the repository at this point in the history
Previously, the done channel was not closed properly in case of an error returned by logPipe.Close(), potentially leading to a goroutine leak. This commit ensures that the done channel is closed even if there's an error during the closing of logPipe.

Signed-off-by: Anton <ant.v.moryakov@gmail.com>
  • Loading branch information
AntonMoryakov committed Apr 25, 2024
1 parent e74ff0f commit 71524dc
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion libcontainer/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func ForwardLogs(logPipe io.ReadCloser) chan error {
}

go func() {
defer close(done)
for s.Scan() {
processEntry(s.Bytes(), logger)
}
Expand All @@ -32,7 +33,6 @@ func ForwardLogs(logPipe io.ReadCloser) chan error {
// The only error we want to return is when reading from
// logPipe has failed.
done <- s.Err()
close(done)
}()

return done
Expand Down

0 comments on commit 71524dc

Please sign in to comment.