Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace time.After with timer; add max retry backoff #919

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions warp/aggregator/network_signature_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

const (
initialRetryFetchSignatureDelay = 100 * time.Millisecond
maxRetryFetchSignatureDelay = 5 * time.Second
retryBackoffFactor = 2
)

Expand Down Expand Up @@ -44,17 +45,30 @@ func (s *NetworkSigner) GetSignature(ctx context.Context, nodeID ids.NodeID, uns
}

delay := initialRetryFetchSignatureDelay
for ctx.Err() == nil {
timer := time.NewTimer(delay)
defer timer.Stop()
for {
signatureRes, err := s.Client.SendAppRequest(nodeID, signatureReqBytes)
// If the client fails to retrieve a response perform an exponential backoff.
// Note: it is up to the caller to ensure that [ctx] is eventually cancelled
if err != nil {
// Wait until the retry delay has elapsed before retrying.
if !timer.Stop() {
<-timer.C
}
timer.Reset(delay)

select {
case <-ctx.Done():
break
case <-time.After(delay):
return nil, ctx.Err()
case <-timer.C:
}

// Exponential backoff.
delay *= retryBackoffFactor
if delay > maxRetryFetchSignatureDelay {
delay = maxRetryFetchSignatureDelay
}
continue
}

Expand All @@ -69,6 +83,4 @@ func (s *NetworkSigner) GetSignature(ctx context.Context, nodeID ids.NodeID, uns
}
return blsSignature, nil
}

return nil, fmt.Errorf("ctx expired fetching signature for message %s from %s: %w", unsignedWarpMessage.ID(), nodeID, ctx.Err())
}
Loading