Skip to content

Commit

Permalink
fix(pubsub): use MaxInt instead of MaxInt64 for BufferedByteLimit (#6113
Browse files Browse the repository at this point in the history
)

* pubsub: use MaxInt instead of MaxInt64 for BufferedByteLimit

Should fix compatibility with 32-bit architectures.

Closes #6112.

* pubsub: copy over logic for maxInt
  • Loading branch information
fsouza authored Jun 2, 2022
1 parent ef2559a commit 06721e0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pubsub/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"errors"
"fmt"
"log"
"math"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -53,6 +52,13 @@ const (
MaxPublishRequestBytes = 1e7
)

const (
// TODO: math.MaxInt was added in Go 1.17. We should use that once 1.17
// becomes the minimum supported version of Go.
intSize = 32 << (^uint(0) >> 63)
maxInt = 1<<(intSize-1) - 1
)

// ErrOversizedMessage indicates that a message's size exceeds MaxPublishRequestBytes.
var ErrOversizedMessage = bundler.ErrOversizedItem

Expand Down Expand Up @@ -639,7 +645,7 @@ func (t *Topic) initBundler() {
// This is because there's no way to set "unlimited" for BufferedByteLimit,
// and simply setting it to MaxOutstandingBytes occasionally leads to issues where
// BufferedByteLimit is reached even though there are resources available.
t.PublishSettings.BufferedByteLimit = math.MaxInt64
t.PublishSettings.BufferedByteLimit = maxInt
}
if t.PublishSettings.FlowControlSettings.MaxOutstandingMessages > 0 {
fcs.MaxOutstandingMessages = t.PublishSettings.FlowControlSettings.MaxOutstandingMessages
Expand Down

0 comments on commit 06721e0

Please sign in to comment.