Skip to content

Commit 4e1bc02

Browse files
committed
BUG: Rework e5b3fbc patch with signal routine cleanup on reload
1 parent 0502b2a commit 4e1bc02

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

cmd/dataplaneapi/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ func startServer(cfg *configuration.Configuration) (reload configuration.AtomicB
205205
log.Info("HAProxy Data Plane API reloading")
206206
reload.Store(true)
207207
cfg.UnSubscribeAll()
208+
cfg.StopSignalHandler()
208209
dataplaneapi.ContextHandler.Cancel()
209210
err := server.Shutdown()
210211
if err != nil {

configuration/configuration.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ type Configuration struct {
150150
Cmdline AtomicString `yaml:"-"`
151151
MapSync *MapSync `yaml:"-"`
152152
mutex sync.Mutex
153+
shutdownSignal chan os.Signal
154+
reloadSignal chan os.Signal
153155
}
154156

155157
var (

configuration/signals.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,32 @@ func (cn *ChanNotify) notify(numTry int) {
8181
}
8282

8383
func (c *Configuration) InitSignalHandler() {
84-
osSignals := make(chan os.Signal, 1)
85-
signal.Notify(osSignals, syscall.SIGINT, syscall.SIGTERM)
84+
c.shutdownSignal = make(chan os.Signal, 1)
85+
signal.Notify(c.shutdownSignal, syscall.SIGINT, syscall.SIGTERM)
8686

8787
go func() {
88-
sig := <-osSignals
89-
log.Print(sig)
90-
c.Notify.Shutdown.Notify()
88+
for sig := range c.shutdownSignal {
89+
log.Debug("Received signal ", sig)
90+
c.Notify.Shutdown.Notify()
91+
}
9192
}()
9293

93-
osSignals2 := make(chan os.Signal, 1)
94-
signal.Notify(osSignals2, syscall.SIGHUP)
94+
c.reloadSignal = make(chan os.Signal, 1)
95+
signal.Notify(c.reloadSignal, syscall.SIGHUP)
9596

9697
go func() {
97-
for {
98-
<-osSignals2
98+
for sig := range c.reloadSignal {
99+
log.Debug("Received signal ", sig)
99100
c.Notify.Reload.Notify()
100101
}
101102
}()
102103
}
104+
105+
func (c *Configuration) StopSignalHandler() {
106+
log.Debug("Unloading signal handler")
107+
signal.Stop(c.shutdownSignal)
108+
signal.Stop(c.reloadSignal)
109+
signal.Ignore(syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
110+
close(c.shutdownSignal)
111+
close(c.reloadSignal)
112+
}

0 commit comments

Comments
 (0)