From 3ad3a29269858d0b0c5bea9e757287d0486b1bb5 Mon Sep 17 00:00:00 2001 From: Thierry FOURNIER Date: Mon, 19 Jul 2021 00:09:56 +0200 Subject: [PATCH] bugfix: fd-leak when RPC client communication fail (#1009) in function 'ExecutionDone' file 'dkron/grpc_client.go', when the process fails, it use a code path without 'conn.Close()' directive. It seems an error because all code path closes the connexion even when succes is reported. Fix removing all conn.Close() and using defer. Co-authored-by: Thierry Fournier --- dkron/grpc_client.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dkron/grpc_client.go b/dkron/grpc_client.go index 3ea3c1601..498e02c2a 100644 --- a/dkron/grpc_client.go +++ b/dkron/grpc_client.go @@ -78,13 +78,13 @@ func (grpcc *GRPCClient) ExecutionDone(addr string, execution *Execution) error }).Error("grpc: error dialing.") return err } + defer conn.Close() d := proto.NewDkronClient(conn) edr, err := d.ExecutionDone(context.Background(), &proto.ExecutionDoneRequest{Execution: execution.ToProto()}) if err != nil { if err.Error() == fmt.Sprintf("rpc error: code = Unknown desc = %s", ErrNotLeader.Error()) { grpcc.logger.Info("grpc: ExecutionDone forwarded to the leader") - conn.Close() return nil } @@ -100,7 +100,6 @@ func (grpcc *GRPCClient) ExecutionDone(addr string, execution *Execution) error "from": edr.From, "payload": string(edr.Payload), }).Debug("grpc: Response from method") - conn.Close() return nil }