stern / stern

⎈ Multi pod and container log tailing for Kubernetes -- Friendly fork of https://github.com/wercker/stern
Apache License 2.0
3.23k stars 119 forks source link

Panic when context is canceled #265

Closed GeorgeVelocity closed 1 year ago

GeorgeVelocity commented 1 year ago

What happened: Panic occurred when the context is canceled:

E0503 19:14:23.280014   19253 retrywatcher.go:130] "Watch failed" err="context canceled"
panic: send on closed channel

goroutine 324 [running]:
github.com/stern/stern/stern.Run.func3()
    /home/runner/go/pkg/mod/github.com/stern/stern@v1.23.0/stern/stern.go:190 +0x1aa
created by github.com/stern/stern/stern.Run
    /home/runner/go/pkg/mod/github.com/stern/stern@v1.23.0/stern/stern.go:179 +0xcea

What you expected to happen: Not to panic when the context is canceled

How to reproduce it (as minimally and precisely as possible): Initialize stern.Config and run the following:

ctx := context.WithCancel(context.Background())
go func() {
    <-time.After(5 * time.Second)
    cancel()
}()

stern.Run(ctx, config)

Anything else we need to know?: There is actually a race condition so the described bug doesn't always occur. It happens because the error channel is closed without waiting for go routine to finish

Environment:

tksm commented 1 year ago

Thank you for reporting! I believe this issue will be resolved in #267.