Skip to content

Commit

Permalink
shared_client: Bump request id
Browse files Browse the repository at this point in the history
Only fail out if non-conflicting request id can not be found.

This works on the premise that the callers are fine with the request id
being modified at this point. Current use sets a random id just prior to
Exchange call, so this premise is satisfied.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
  • Loading branch information
jrajahalme committed Apr 25, 2024
1 parent d47d0dd commit 2469d2c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions shared_client.go
Expand Up @@ -232,10 +232,19 @@ func handler(wg *sync.WaitGroup, client *Client, conn *Conn, requests chan reque
// Due to birthday paradox and the fact that ID is uint16
// it's likely to happen with small number (~200) of concurrent requests
// which would result in goroutine leak as we would never close req.ch
if _, ok := waitingResponses[req.msg.Id]; ok {
req.ch <- sharedClientResponse{nil, 0, fmt.Errorf("duplicate request id %d", req.msg.Id)}
close(req.ch)
continue
if _, duplicate := waitingResponses[req.msg.Id]; duplicate {
// find next available ID
for id := req.msg.Id + 1; id != req.msg.Id; id++ {
if _, duplicate = waitingResponses[id]; !duplicate {
req.msg.Id = id
break
}
}
if duplicate {
req.ch <- sharedClientResponse{nil, 0, fmt.Errorf("duplicate request id %d", req.msg.Id)}
close(req.ch)
continue
}
}

err := client.SendContext(req.ctx, req.msg, conn, start)
Expand Down

0 comments on commit 2469d2c

Please sign in to comment.