Skip to content

Commit 57b885b

Browse files
authored
Better pushback messages (#324)
* better pushback * Unbounded nit
1 parent 47bb8ca commit 57b885b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

internal/ct/handlers.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import (
2121
"errors"
2222
"fmt"
2323
"io"
24+
"math/rand/v2"
2425
"net/http"
26+
"strconv"
2527
"strings"
2628
"sync"
2729
"time"
@@ -282,8 +284,8 @@ func addChainInternal(ctx context.Context, opts *HandlerOptions, log *log, w htt
282284
index, dedupedTimeMillis, err := log.storage.Add(ctx, entry)
283285
if err != nil {
284286
if errors.Is(err, tessera.ErrPushback) {
285-
w.Header().Add("Retry-After", "1")
286-
return http.StatusServiceUnavailable, nil, fmt.Errorf("received pushback from Tessera sequencer: %v", err)
287+
w.Header().Add("Retry-After", strconv.Itoa(rand.IntN(5)+1)) // random retry within [1,6) seconds
288+
return http.StatusTooManyRequests, nil, errors.New(http.StatusText(http.StatusTooManyRequests))
287289
}
288290
return http.StatusInternalServerError, nil, fmt.Errorf("couldn't store the leaf: %v", err)
289291
}

0 commit comments

Comments
 (0)