mirror of
https://github.com/minio/minio.git
synced 2025-11-07 21:02:58 -05:00
avoid close 'nil' panics if any (#18890)
brings a generic implementation that prints a stack trace for 'nil' channel closes(), if not safely closes it.
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -418,3 +419,13 @@ func CopyAligned(w io.Writer, r io.Reader, alignedBuf []byte, totalSize int64, f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SafeClose safely closes any channel of any type
|
||||
func SafeClose[T any](c chan<- T) {
|
||||
if c != nil {
|
||||
close(c)
|
||||
}
|
||||
// Print stack to check who is sending `c` as `nil`
|
||||
// without crashing the server.
|
||||
debug.PrintStack()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user