Skip to content

Commit

Permalink
respond early
Browse files Browse the repository at this point in the history
  • Loading branch information
Cory Schwartz committed Apr 20, 2022
1 parent fc42d03 commit 9558e9f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gateway/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,12 @@ func (gw *Node) checkTimestamp(at time.Time) error {
func (gw *Node) limit(ctx context.Context, tokens int) error {
ctx2, cancel := context.WithTimeout(ctx, gw.rateLimitTimeout)
defer cancel()
if !gw.rateLimiter.AllowN(time.Now(), tokens) {
return fmt.Errorf("server busy")
}
err := gw.rateLimiter.WaitN(ctx2, tokens)
if err != nil {
return fmt.Errorf("rate limited: %w", err)
return fmt.Errorf("server busy, cannot complete before timeout %w", err)
}
return nil
}
Expand Down

0 comments on commit 9558e9f

Please sign in to comment.