Skip to content

Commit

Permalink
sigpipe signal handling fix (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongfei605 authored Jun 26, 2023
1 parent a1fb8f4 commit 47b200e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,18 +651,15 @@ func Start() {
{
// Termination handler.
term := make(chan os.Signal, 1)
signal.Notify(term, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGPIPE)
signal.Notify(term, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
cancel := make(chan struct{})
g.Add(
func() error {
// Don't forget to release the reloadReady channel so that waiting blocks can exit normally.
select {
case sig := <-term:
level.Warn(logger).Log("msg", "Received "+sig.String())
if sig != syscall.SIGPIPE {
level.Warn(logger).Log("msg", "exiting gracefully...")
reloadReady.Close()
}
level.Warn(logger).Log("msg", "Received "+sig.String()+" exiting gracefully...")
reloadReady.Close()
case <-webHandler.Quit():
level.Warn(logger).Log("msg", "Received termination request via web service, exiting gracefully...")
case <-cancel:
Expand Down Expand Up @@ -734,15 +731,19 @@ func Start() {
// Make sure that sighup handler is registered with a redirect to the channel before the potentially
// long and synchronous tsdb init.
hup := make(chan os.Signal, 1)
signal.Notify(hup, syscall.SIGHUP)
signal.Notify(hup, syscall.SIGHUP, syscall.SIGPIPE)
cancel := make(chan struct{})
g.Add(
func() error {
<-reloadReady.C

for {
select {
case <-hup:
case ch := <-hup:
if ch == syscall.SIGPIPE {
// broken pipe , do nothing
continue
}
if err := reloadConfig(cfg.configFile, cfg.enableExpandExternalLabels, cfg.tsdb.EnableExemplarStorage, logger, reloaders...); err != nil {
level.Error(logger).Log("msg", "Error reloading config", "err", err)
}
Expand Down

0 comments on commit 47b200e

Please sign in to comment.