Repository: influxdata/influxdb-client-go (go)

Issue:
Retries are attempted even if MaxRetries is set to zero
<!--

Thank you for reporting a bug. 

* Please add a :+1: or comment on a similar existing bug report instead of opening a new one.
    * https://github.com/influxdata/influxdb-client-go/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+is%3Aclosed+sort%3Aupdated-desc+label%3Abug+
* Please check whether the bug can be reproduced with the latest release.
* The fastest way to fix a bug is to open a Pull Request.
    * https://github.com/influxdata/influxdb-client-go/pulls

-->

__Steps to reproduce:__
Given the following client code snippet

```
	options := influxdb2.DefaultOptions().SetMaxRetries(0)
	client := influxdb2.NewClientWithOptions(url, authToken, options)
	defer client.Close()
	writeAPI := client.WriteAPIBlocking("", dbName)
        err := writeAPI.WritePoint(context.Background(), point)
        if err != nil {
            fmt.Printf("Error: %v", err)
        }
```

where `url` is the URL of an InfluxDB instance that is unreachable (i.e. results in a connection error), the `WritePoint()` method may attempt an implicit deferred retry (instead of immediately returning a connection error), even though MaxRetries was set to 0.

__Expected behavior:__
The `WritePoint()` method should always return an error in this case.

__Actual behavior:__
No error is returned.

__Specifications:__
 - Client Version: 2.2.2
 - InfluxDB Version: n/a (testing against an unreachable InfluxDB instance)
 - Platform: MacOS 10.15.7


Pull request description:
fix: don't attempt retries if MaxRetries is set to zero
Closes #236 

## Proposed Changes

When a write error occurs, explicitly test for `MaxRetries()` being zero, and do not proceed with retry logic if this is the case.

## Checklist

<!-- Checkboxes below this note can be erased if not applicable to your Pull Request. -->

- [ ] CHANGELOG.md updated
- [x] Rebased/mergeable
- [x] A test has been added if appropriate
- [x] Tests pass
- [x] Commit messages are in [semantic format](https://seesparkbox.com/foundry/semantic_commit_messages)
- [ ] Sign [CLA](https://influxdata.com/community/cla/) (if not already signed)


Patch:
diff --git a/internal/write/service.go b/internal/write/service.go
index 51034a1..80397b3 100644
--- a/internal/write/service.go
+++ b/internal/write/service.go
@@ -99,7 +99,7 @@ func (w *Service) HandleWrite(ctx context.Context, batch *Batch) error {
 		if batchToWrite != nil {
 			perror := w.WriteBatch(ctx, batchToWrite)
 			if perror != nil {
-				if perror.StatusCode == 0 || perror.StatusCode >= http.StatusTooManyRequests {
+				if w.writeOptions.MaxRetries() != 0 && (perror.StatusCode == 0 || perror.StatusCode >= http.StatusTooManyRequests) {
 					log.Errorf("Write error: %s\nBatch kept for retrying\n", perror.Error())
 					if perror.RetryAfter > 0 {
 						batchToWrite.retryDelay = perror.RetryAfter * 1000


Test patch:
diff --git a/internal/write/service_test.go b/internal/write/service_test.go
index bb7ec7e..cfad875 100644
--- a/internal/write/service_test.go
+++ b/internal/write/service_test.go
@@ -259,3 +259,21 @@ func TestRetryOnConnectionError(t *testing.T) {
 	assert.Equal(t, "4", hs.Lines()[3])
 
 }
+
+func TestNoRetryIfMaxRetriesIsZero(t *testing.T) {
+	log.Log.SetLogLevel(log.DebugLevel)
+	hs := test.NewTestService(t, "http://localhost:8086")
+	//
+	opts := write.DefaultOptions().SetMaxRetries(0)
+	ctx := context.Background()
+	srv := NewService("my-org", "my-bucket", hs, opts)
+
+	hs.SetReplyError(&http.Error{
+		Err: errors.New("connection refused"),
+	})
+
+	b1 := NewBatch("1\n", opts.RetryInterval())
+	err := srv.HandleWrite(ctx, b1)
+	assert.NotNil(t, err)
+	assert.Equal(t, 0, srv.retryQueue.list.Len())
+}