Skip to content

Commit

Permalink
gracefully handle overflow of request timeout (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjaybv committed Aug 6, 2021
1 parent e403d62 commit c5db2e4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions handlers.go
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io"
"io/ioutil"
"math"
"net/http"
"sort"
"strconv"
Expand Down Expand Up @@ -402,6 +403,10 @@ func invokeRPC(ctx context.Context, methodName string, ch grpcdynamic.Channel, d
if input.TimeoutSeconds > 0 {
var cancel context.CancelFunc
timeout := time.Duration(input.TimeoutSeconds * float32(time.Second))
// If the timeout is too huge that it overflows int64, cap it off.
if timeout < 0 {
timeout = time.Duration(math.MaxInt64)
}
ctx, cancel = context.WithTimeout(ctx, timeout)
defer cancel()
}
Expand Down

0 comments on commit c5db2e4

Please sign in to comment.