From af4ec80649d33e73532dfb62d4266b64d9ae932c Mon Sep 17 00:00:00 2001 From: tarat44 <32471142+tarat44@users.noreply.github.com> Date: Thu, 29 Apr 2021 18:05:50 -0400 Subject: [PATCH] create separate function with its own context to shutdown http2 client conn in h2ping check --- agent/checks/check.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/agent/checks/check.go b/agent/checks/check.go index e2417709a..78a98b61e 100644 --- a/agent/checks/check.go +++ b/agent/checks/check.go @@ -522,6 +522,17 @@ type CheckH2PING struct { 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() { t := &http2.Transport{ TLSClientConfig: c.TLSClientConfig, @@ -540,9 +551,9 @@ func (c *CheckH2PING) check() { c.StatusHandler.updateCheck(c.CheckID, api.HealthCritical, message) return } + defer shutdownHTTP2ClientConn(clientConn, c.Timeout, c.CheckID.String(), c.Logger) ctx, cancel := context.WithTimeout(context.Background(), c.Timeout) defer cancel() - defer clientConn.Shutdown(ctx) err = clientConn.Ping(ctx) if err == nil { c.StatusHandler.updateCheck(c.CheckID, api.HealthPassing, "HTTP2 ping was successful")