Skip to content

Commit

Permalink
fix(client): try reconnect after a reconnection attempt failure
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Henri Symoneaux <[email protected]>
  • Loading branch information
phsym committed Feb 5, 2025
1 parent a47ea0d commit 9bffea4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion kmipclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ func (c *Client) Close() error {

func (c *Client) reconnect(ctx context.Context) error {
// fmt.Println("Reconnecting")
c.conn.Close()
if c.conn != nil {
c.conn.Close()
c.conn = nil
}
stream, err := c.dialer(ctx)
if err != nil {
return err
Expand All @@ -277,6 +280,11 @@ func (c *Client) reconnect(ctx context.Context) error {
func (c *Client) doRountrip(ctx context.Context, msg *kmip.RequestMessage) (*kmip.ResponseMessage, error) {
c.lock.Lock()
defer c.lock.Unlock()
if c.conn == nil {
if err := c.reconnect(ctx); err != nil {
return nil, err
}
}

//TODO: Better reconnection loop. Do we really need a retry counter here ?
retry := 3
Expand Down

0 comments on commit 9bffea4

Please sign in to comment.