未验证 提交 8b64b70f 编写于 作者: M Mitsuo Heijo 提交者: GitHub

Guard closing quitCh with sync.Once to prevent double close (#8242)

* Guard closing quitCh with sync.Once to prevent double close
Signed-off-by: NMitsuo Heijo <mitsuo.heijo@gmail.com>
上级 acee998d
......@@ -186,6 +186,7 @@ type Handler struct {
router *route.Router
quitCh chan struct{}
quitOnce sync.Once
reloadCh chan chan error
options *Options
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) {
select {
case <-h.quitCh:
fmt.Fprintf(w, "Termination already in progress.")
default:
fmt.Fprintf(w, "Requesting termination... Goodbye!")
var closed bool
h.quitOnce.Do(func() {
closed = true
close(h.quitCh)
fmt.Fprintf(w, "Requesting termination... Goodbye!")
})
if !closed {
fmt.Fprintf(w, "Termination already in progress.")
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册