Skip to content

Commit

Permalink
fix increase default BufferSize for bufio.Scanner (minio#1272)
Browse files Browse the repository at this point in the history
Use a higher buffer to handle proxy caching
issues might occur.
  • Loading branch information
harshavardhana authored Apr 17, 2020
1 parent d624b8a commit 33e5528
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api-notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ type NotificationInfo struct {
// ListenBucketNotification - listen on bucket notifications.
func (c Client) ListenBucketNotification(bucketName, prefix, suffix string, events []string, doneCh <-chan struct{}) <-chan NotificationInfo {
notificationInfoCh := make(chan NotificationInfo, 1)
const notificationCapacity = 1024 * 1024
notificationEventBuffer := make([]byte, notificationCapacity)
// Only success, start a routine to start reading line by line.
go func(notificationInfoCh chan<- NotificationInfo) {
defer close(notificationInfoCh)
Expand Down Expand Up @@ -198,6 +200,10 @@ func (c Client) ListenBucketNotification(bucketName, prefix, suffix string, even
// Initialize a new bufio scanner, to read line by line.
bio := bufio.NewScanner(resp.Body)

// Use a higher buffer to support unexpected
// caching done by proxies
bio.Buffer(notificationEventBuffer, notificationCapacity)

// Unmarshal each line, returns marshalled values.
for bio.Scan() {
var notificationInfo NotificationInfo
Expand Down

0 comments on commit 33e5528

Please sign in to comment.