From 9df4e4ee2992350192781a683bbfc453add1d18e Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Sat, 15 Apr 2023 16:18:58 +0100 Subject: [PATCH] listen bucket: Support empty events from the server Ask the server to send empty events to clear the buffer scanner which can be filled with whitespaces but without new lines when the bucket is idle and without any events --- api-bucket-notification.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api-bucket-notification.go b/api-bucket-notification.go index dc37b0c07..6c9b4deb0 100644 --- a/api-bucket-notification.go +++ b/api-bucket-notification.go @@ -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", "true") urlValues.Set("prefix", prefix) urlValues.Set("suffix", suffix) urlValues["events"] = events @@ -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: