Skip to content

Commit

Permalink
fix: panic in Logger.Stop (#9159)
Browse files Browse the repository at this point in the history
There was a panic being caused in Logger.Stop() (Possibly from 97de7db) because threadLogsCancel might be nil if Stop was called before Start, this just initialises it to a noop function.
  • Loading branch information
mboulton-fathom authored Nov 14, 2023
1 parent be6b6aa commit 1f591ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/skaffold/docker/logger/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func NewLogger(ctx context.Context, tracker *tracker.ContainerTracker, cfg docke
client: cli,
colorPicker: output.NewColorPicker(),
shouldInterruptLogs: shouldInterruptLogs,
threadLogsCancel: func() {},
}, nil
}

Expand Down
17 changes: 17 additions & 0 deletions pkg/skaffold/docker/logger/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import (
"context"
"io"
"testing"

"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/docker/tracker"
"github.com/GoogleContainerTools/skaffold/v2/testutil"
)

func TestDockerLoggerZeroValue(t *testing.T) {
Expand All @@ -31,3 +35,16 @@ func TestDockerLoggerZeroValue(t *testing.T) {
m.Unmute()
m.Stop()
}

func TestLoggerStopNoPanic(t *testing.T) {
testutil.Run(t, "stopping logger should not panic", func(t *testutil.T) {
t.Override(&docker.NewAPIClient, func(context.Context, docker.Config) (docker.LocalDaemon, error) {
return nil, nil
})

logger, err := NewLogger(context.Background(), &tracker.ContainerTracker{}, nil, true)
testutil.CheckError(t.T, false, err)

logger.Stop()
})
}

0 comments on commit 1f591ba

Please sign in to comment.