mirror of
https://github.com/status-im/consul.git
synced 2025-02-02 00:46:43 +00:00
create separate function with its own context to shutdown http2 client conn in h2ping check
This commit is contained in:
parent
1ca5fa9769
commit
51f8db3879
@ -522,6 +522,17 @@ type CheckH2PING struct {
|
|||||||
stopWg sync.WaitGroup
|
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() {
|
||||||
t := &http2.Transport{
|
t := &http2.Transport{
|
||||||
TLSClientConfig: c.TLSClientConfig,
|
TLSClientConfig: c.TLSClientConfig,
|
||||||
@ -540,9 +551,9 @@ 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()
|
||||||
defer clientConn.Shutdown(ctx)
|
|
||||||
err = clientConn.Ping(ctx)
|
err = clientConn.Ping(ctx)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
c.StatusHandler.updateCheck(c.CheckID, api.HealthPassing, "HTTP2 ping was successful")
|
c.StatusHandler.updateCheck(c.CheckID, api.HealthPassing, "HTTP2 ping was successful")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user