summaryrefslogtreecommitdiff
path: root/api-notification.go
diff options
context:
space:
mode:
authorFélix Sipma <felix+debian@gueux.org>2019-11-23 20:49:18 +0100
committerFélix Sipma <felix+debian@gueux.org>2019-11-23 20:49:18 +0100
commitb75e2eba23b61af62951c5a5fc45f3eb4ffe68f3 (patch)
treeaa00eb410cd0f8f470823f6347ea3213283e93f0 /api-notification.go
parent70b5c53e64dae38106cf7e218cc99e6f493f12b9 (diff)
New upstream version 6.0.43
Diffstat (limited to 'api-notification.go')
-rw-r--r--api-notification.go37
1 files changed, 20 insertions, 17 deletions
diff --git a/api-notification.go b/api-notification.go
index 1c01e36..0480c21 100644
--- a/api-notification.go
+++ b/api-notification.go
@@ -1,6 +1,6 @@
/*
- * Minio Go Library for Amazon S3 Compatible Cloud Storage
- * Copyright 2017 Minio, Inc.
+ * MinIO Go Library for Amazon S3 Compatible Cloud Storage
+ * Copyright 2017 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,12 +21,11 @@ import (
"bufio"
"context"
"encoding/json"
- "io"
"net/http"
"net/url"
"time"
- "github.com/minio/minio-go/pkg/s3utils"
+ "github.com/minio/minio-go/v6/pkg/s3utils"
)
// GetBucketNotification - get bucket notification at a given path.
@@ -164,13 +163,14 @@ func (c Client) ListenBucketNotification(bucketName, prefix, suffix string, even
// Indicate to our routine to exit cleanly upon return.
defer close(retryDoneCh)
+ // Prepare urlValues to pass into the request on every loop
+ urlValues := make(url.Values)
+ urlValues.Set("prefix", prefix)
+ urlValues.Set("suffix", suffix)
+ urlValues["events"] = events
+
// Wait on the jitter retry loop.
for range c.newRetryTimerContinous(time.Second, time.Second*30, MaxJitter, retryDoneCh) {
- urlValues := make(url.Values)
- urlValues.Set("prefix", prefix)
- urlValues.Set("suffix", suffix)
- urlValues["events"] = events
-
// Execute GET on bucket to list objects.
resp, err := c.executeMethod(context.Background(), "GET", requestMetadata{
bucketName: bucketName,
@@ -196,30 +196,33 @@ func (c Client) ListenBucketNotification(bucketName, prefix, suffix string, even
// Initialize a new bufio scanner, to read line by line.
bio := bufio.NewScanner(resp.Body)
- // Close the response body.
- defer resp.Body.Close()
-
// Unmarshal each line, returns marshalled values.
for bio.Scan() {
var notificationInfo NotificationInfo
if err = json.Unmarshal(bio.Bytes(), &notificationInfo); err != nil {
+ // Unexpected error during json unmarshal, send
+ // the error to caller for actionable as needed.
+ notificationInfoCh <- NotificationInfo{
+ Err: err,
+ }
+ closeResponse(resp)
continue
}
// Send notificationInfo
select {
case notificationInfoCh <- notificationInfo:
case <-doneCh:
+ closeResponse(resp)
return
}
}
- // Look for any underlying errors.
if err = bio.Err(); err != nil {
- // For an unexpected connection drop from server, we close the body
- // and re-connect.
- if err == io.ErrUnexpectedEOF {
- resp.Body.Close()
+ notificationInfoCh <- NotificationInfo{
+ Err: err,
}
}
+ // Close current connection before looping further.
+ closeResponse(resp)
}
}(notificationInfoCh)