Skip to content

Commit

Permalink
bugfix: fd-leak when RPC client communication fail (#1009)
Browse files Browse the repository at this point in the history
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 <thierry.fournier@ozon.io>
  • Loading branch information
thierry-f-78 and thierry-f-78 committed Jul 18, 2021
1 parent bfef6b7 commit 3ad3a29
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions dkron/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 3ad3a29

Please sign in to comment.