Skip to content

Commit

Permalink
listen bucket: Support empty events from the server
Browse files Browse the repository at this point in the history
Ask the server to send empty events.

With older MinIO versions, this would clear the whitespaces for the
scanner buffer, many whitespaces will make the scanner complains as it
needs a new line to clear some internal buffer.

With new MinIO version, ping=10 query will be considered and the server
will send empty events, instead of the whitespaces, each 10 seconds.
  • Loading branch information
Anis Elleuch committed Apr 19, 2023
1 parent 0bf84b3 commit d841110
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions api-bucket-notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func (c *Client) ListenBucketNotification(ctx context.Context, bucketName, prefi

// Prepare urlValues to pass into the request on every loop
urlValues := make(url.Values)
urlValues.Set("ping", "10")
urlValues.Set("prefix", prefix)
urlValues.Set("suffix", suffix)
urlValues["events"] = events
Expand Down Expand Up @@ -224,6 +225,12 @@ func (c *Client) ListenBucketNotification(ctx context.Context, bucketName, prefi
closeResponse(resp)
continue
}

// Empty events pinged from the server
if len(notificationInfo.Records) == 0 && notificationInfo.Err == nil {
continue
}

// Send notificationInfo
select {
case notificationInfoCh <- notificationInfo:
Expand Down

0 comments on commit d841110

Please sign in to comment.