mirror of
https://github.com/status-im/consul.git
synced 2025-02-20 01:18:49 +00:00
Merge pull request #9995 from tarat44/fix-close-h2ping-client-connections
Add graceful shutdown of client connection and WaitGroup to H2PING
This commit is contained in:
commit
7bc4a59177
@ -519,6 +519,18 @@ type CheckH2PING struct {
|
|||||||
stop bool
|
stop bool
|
||||||
stopCh chan struct{}
|
stopCh chan struct{}
|
||||||
stopLock sync.Mutex
|
stopLock sync.Mutex
|
||||||
|
stopWg sync.WaitGroup
|
||||||
|
}
|
||||||
|
|
||||||
|
func shutdownHTTP2ClientConn(clientConn *http2.ClientConn, timeout time.Duration, checkIDString string, logger hclog.Logger) {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), timeout/2)
|
||||||
|
defer cancel()
|
||||||
|
err := clientConn.Shutdown(ctx)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warn("Shutdown of H2Ping check client connection gave an error",
|
||||||
|
"check", checkIDString,
|
||||||
|
"error", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CheckH2PING) check() {
|
func (c *CheckH2PING) check() {
|
||||||
@ -539,6 +551,7 @@ func (c *CheckH2PING) check() {
|
|||||||
c.StatusHandler.updateCheck(c.CheckID, api.HealthCritical, message)
|
c.StatusHandler.updateCheck(c.CheckID, api.HealthCritical, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer shutdownHTTP2ClientConn(clientConn, c.Timeout, c.CheckID.String(), c.Logger)
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), c.Timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), c.Timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
err = clientConn.Ping(ctx)
|
err = clientConn.Ping(ctx)
|
||||||
@ -558,9 +571,11 @@ func (c *CheckH2PING) Stop() {
|
|||||||
c.stop = true
|
c.stop = true
|
||||||
close(c.stopCh)
|
close(c.stopCh)
|
||||||
}
|
}
|
||||||
|
c.stopWg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CheckH2PING) run() {
|
func (c *CheckH2PING) run() {
|
||||||
|
defer c.stopWg.Done()
|
||||||
// Get the randomized initial pause time
|
// Get the randomized initial pause time
|
||||||
initialPauseTime := lib.RandomStagger(c.Interval)
|
initialPauseTime := lib.RandomStagger(c.Interval)
|
||||||
next := time.After(initialPauseTime)
|
next := time.After(initialPauseTime)
|
||||||
@ -583,6 +598,7 @@ func (c *CheckH2PING) Start() {
|
|||||||
}
|
}
|
||||||
c.stop = false
|
c.stop = false
|
||||||
c.stopCh = make(chan struct{})
|
c.stopCh = make(chan struct{})
|
||||||
|
c.stopWg.Add(1)
|
||||||
go c.run()
|
go c.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user