mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Guard closing quitCh with sync.Once to prevent double close (#8242)
* Guard closing quitCh with sync.Once to prevent double close Signed-off-by: Mitsuo Heijo <mitsuo.heijo@gmail.com>
This commit is contained in:
parent
acee998df6
commit
8b64b70fe4
13
web/web.go
13
web/web.go
|
@ -186,6 +186,7 @@ type Handler struct {
|
||||||
|
|
||||||
router *route.Router
|
router *route.Router
|
||||||
quitCh chan struct{}
|
quitCh chan struct{}
|
||||||
|
quitOnce sync.Once
|
||||||
reloadCh chan chan error
|
reloadCh chan chan error
|
||||||
options *Options
|
options *Options
|
||||||
config *config.Config
|
config *config.Config
|
||||||
|
@ -918,12 +919,14 @@ func (h *Handler) version(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) quit(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) quit(w http.ResponseWriter, r *http.Request) {
|
||||||
select {
|
var closed bool
|
||||||
case <-h.quitCh:
|
h.quitOnce.Do(func() {
|
||||||
fmt.Fprintf(w, "Termination already in progress.")
|
closed = true
|
||||||
default:
|
|
||||||
fmt.Fprintf(w, "Requesting termination... Goodbye!")
|
|
||||||
close(h.quitCh)
|
close(h.quitCh)
|
||||||
|
fmt.Fprintf(w, "Requesting termination... Goodbye!")
|
||||||
|
})
|
||||||
|
if !closed {
|
||||||
|
fmt.Fprintf(w, "Termination already in progress.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue