diff options
author | Bjørn Erik Pedersen <[email protected]> | 2023-04-13 11:44:22 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2023-04-13 11:44:22 +0200 |
commit | 9906c1ae52e44f2e8ed45873ea36cd83a9e9bcc0 (patch) | |
tree | 2ddf2af8abbd12710c58e16ac6a6066f3b853587 /deps | |
parent | 5596dc24a0adc8907f52886a8e035e1bcd66dd8d (diff) | |
download | hugo-9906c1ae52e44f2e8ed45873ea36cd83a9e9bcc0.tar.gz hugo-9906c1ae52e44f2e8ed45873ea36cd83a9e9bcc0.zip |
Prevent the global error collector to panic when sending on closed channel
Diffstat (limited to 'deps')
-rw-r--r-- | deps/deps.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/deps/deps.go b/deps/deps.go index 7b252d020..511ee885c 100644 --- a/deps/deps.go +++ b/deps/deps.go @@ -119,6 +119,8 @@ type Deps struct { type globalErrHandler struct { // Channel for some "hard to get to" build errors buildErrors chan error + // Used to signal that the build is done. + quit chan struct{} } // SendErr sends the error on a channel to be handled later. @@ -127,6 +129,7 @@ type globalErrHandler struct { func (e *globalErrHandler) SendError(err error) { if e.buildErrors != nil { select { + case <-e.quit: case e.buildErrors <- err: default: } @@ -137,10 +140,18 @@ func (e *globalErrHandler) SendError(err error) { } func (e *globalErrHandler) StartErrorCollector() chan error { + e.quit = make(chan struct{}) e.buildErrors = make(chan error, 10) return e.buildErrors } +func (e *globalErrHandler) StopErrorCollector() { + if e.buildErrors != nil { + close(e.quit) + close(e.buildErrors) + } +} + // Listeners represents an event listener. type Listeners struct { sync.Mutex |