From 2b2bdcb4ad163970c5814419db19b5add6202008 Mon Sep 17 00:00:00 2001 From: Malte Bauch <malte.bauch@h-da.de> Date: Tue, 5 Nov 2024 16:12:43 +0100 Subject: [PATCH] Use grpc timeout for healthcheck --- goKMS/kms/peers/kmsPeer.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/goKMS/kms/peers/kmsPeer.go b/goKMS/kms/peers/kmsPeer.go index 88a3f712..bf1c6780 100644 --- a/goKMS/kms/peers/kmsPeer.go +++ b/goKMS/kms/peers/kmsPeer.go @@ -116,7 +116,6 @@ func NewKmsPeer(peerKmsId string, quantummodule QuantumModule, cryptoAlgorithm c } func (kp *KmsPeer) initializeHealthCheck(remoteConn *grpc.ClientConn) { - timeout := time.Second * 5 defer func() { if err := remoteConn.Close(); err != nil { log.Errorf("Failed to close health check connection, for peer: %s; err: %v", kp.peerKmsId, err) @@ -126,7 +125,7 @@ func (kp *KmsPeer) initializeHealthCheck(remoteConn *grpc.ClientConn) { healthClient := healthpb.NewHealthClient(remoteConn) // TODO: add option to cancel for range time.Tick(time.Second) { - ctx, cancel := context.WithTimeout(context.Background(), timeout) + ctx, cancel := context.WithTimeout(context.Background(), kp.gRPCTimeout) resp, err := healthClient.Check(ctx, &healthpb.HealthCheckRequest{Service: ""}) cancel() if err != nil { @@ -140,7 +139,7 @@ func (kp *KmsPeer) initializeHealthCheck(remoteConn *grpc.ClientConn) { } break } else if stat, ok := status.FromError(err); ok && stat.Code() == codes.DeadlineExceeded { - log.Printf("health request for peer: %s timed out after %d seconds", kp.peerKmsId, timeout) + log.Printf("health request for peer: %s timed out after %d seconds", kp.peerKmsId, kp.gRPCTimeout) if kp.peerStatus != KmsPeerDown { kp.peerStatus = KmsPeerDown if err := kp.eventBus.Publish(event.NewPeerEvent(kp.TcpSocketStr)); err != nil { -- GitLab