Skip to content

Commit 1cc8d97

Browse files
committed
Allow "0" to disable http_client_timeout
1 parent dea6304 commit 1cc8d97

9 files changed

Lines changed: 57 additions & 0 deletions

File tree

alioss/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ The AliOSS client requires a JSON configuration file with the following structur
2020
}
2121
```
2222

23+
Set `http_request_timeout` to `"0"` to disable the HTTP client timeout explicitly.
24+
2325
**Usage examples:**
2426
``` bash
2527
# Upload a blob

alioss/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ func (c AliStorageConfig) HTTPRequestTimeoutSeconds() (int64, error) {
4646
return defaultHTTPRequestTimeoutSeconds, nil
4747
}
4848

49+
if c.HTTPRequestTimeout == "0" {
50+
return 0, nil
51+
}
52+
4953
httpRequestTimeout, err := time.ParseDuration(c.HTTPRequestTimeout)
5054
if err != nil {
5155
return 0, fmt.Errorf("invalid http_request_timeout: %w", err)

alioss/config/config_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ var _ = Describe("Config", func() {
7979
Expect(err.Error()).To(ContainSubstring("invalid http_request_timeout"))
8080
})
8181

82+
It("disables timeout when http_request_timeout is set to 0", func() {
83+
configJson := []byte(`{"access_key_id": "foo_access_key_id",
84+
"access_key_secret": "foo_access_key_secret",
85+
"endpoint": "foo_endpoint",
86+
"bucket_name": "foo_bucket_name",
87+
"http_request_timeout": "0"}`)
88+
configReader := bytes.NewReader(configJson)
89+
90+
cfg, err := config.NewFromReader(configReader)
91+
Expect(err).ToNot(HaveOccurred())
92+
timeoutSeconds, err := cfg.HTTPRequestTimeoutSeconds()
93+
Expect(err).ToNot(HaveOccurred())
94+
Expect(timeoutSeconds).To(BeZero())
95+
})
96+
8297
It("returns an error when http_request_timeout is non-positive", func() {
8398
configJson := []byte(`{"access_key_id": "foo_access_key_id",
8499
"access_key_secret": "foo_access_key_secret",

gcs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ The GCS client requires a JSON configuration file.
2323
}
2424
```
2525

26+
Set `http_request_timeout` to `"0"` to disable the HTTP client timeout explicitly.
27+
2628
### Credentials Source Types
2729
* **"":** specifies that credentials should be detected. Application Default Credentials will be used if avaliable. A read-only client will be used otherwise.
2830
* **"none":** specifies that credentials are explicitly empty and that the client should be restricted to a read-only scope.

gcs/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ func (c *GCSCli) HTTPRequestTimeoutValue() (time.Duration, error) {
134134
return defaultHTTPRequestTimeout, nil
135135
}
136136

137+
if c.HTTPRequestTimeout == "0" {
138+
return 0, nil
139+
}
140+
137141
requestTimeout, err := time.ParseDuration(c.HTTPRequestTimeout)
138142
if err != nil {
139143
return 0, fmt.Errorf("invalid http_request_timeout: %w", err)

gcs/config/config_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,19 @@ var _ = Describe("BlobstoreClient configuration", func() {
208208
})
209209
})
210210

211+
Describe("when http_request_timeout is set to 0", func() {
212+
dummyJSONBytes := []byte(`{"bucket_name": "some-bucket", "http_request_timeout":"0"}`)
213+
dummyJSONReader := bytes.NewReader(dummyJSONBytes)
214+
215+
It("disables timeout", func() {
216+
c, err := NewFromReader(dummyJSONReader)
217+
Expect(err).To(BeNil())
218+
requestTimeoutValue, err := c.HTTPRequestTimeoutValue()
219+
Expect(err).To(BeNil())
220+
Expect(requestTimeoutValue).To(BeZero())
221+
})
222+
})
223+
211224
Describe("when http_request_timeout is non-positive", func() {
212225
dummyJSONBytes := []byte(`{"bucket_name": "some-bucket", "http_request_timeout":"0s"}`)
213226
dummyJSONReader := bytes.NewReader(dummyJSONBytes)

s3/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ The S3 client requires a JSON configuration file with the following structure:
3838
}
3939
```
4040

41+
Set `http_request_timeout` to `"0"` to disable the HTTP client timeout explicitly.
42+
4143
**Usage examples:**
4244
```shell
4345
# Upload a file to S3

s3/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ func (c *S3Cli) HTTPRequestTimeoutValue() (time.Duration, error) {
269269
return defaultHTTPRequestTimeout, nil
270270
}
271271

272+
if c.HTTPRequestTimeout == "0" {
273+
return 0, nil
274+
}
275+
272276
httpRequestTimeout, err := time.ParseDuration(c.HTTPRequestTimeout)
273277
if err != nil {
274278
return 0, fmt.Errorf("invalid http_request_timeout: %w", err)

s3/config/config_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,17 @@ var _ = Describe("BlobstoreClient configuration", func() {
421421
Expect(timeout.Seconds()).To(Equal(45.0))
422422
})
423423

424+
It("disables timeout when set to 0", func() {
425+
dummyJSONBytes := []byte(`{"access_key_id":"id","secret_access_key":"key","bucket_name":"some-bucket","http_request_timeout":"0"}`)
426+
dummyJSONReader := bytes.NewReader(dummyJSONBytes)
427+
428+
c, err := config.NewFromReader(dummyJSONReader)
429+
Expect(err).ToNot(HaveOccurred())
430+
timeout, err := c.HTTPRequestTimeoutValue()
431+
Expect(err).ToNot(HaveOccurred())
432+
Expect(timeout).To(BeZero())
433+
})
434+
424435
It("rejects invalid duration formats", func() {
425436
dummyJSONBytes := []byte(`{"access_key_id":"id","secret_access_key":"key","bucket_name":"some-bucket","http_request_timeout":"bananas"}`)
426437
dummyJSONReader := bytes.NewReader(dummyJSONBytes)

0 commit comments

Comments
 (0)