Skip to content

Commit b85eff2

Browse files
authored
Merge branch 'main' into fix/539
Signed-off-by: Daniel (dB.) Doubrovkine <[email protected]>
2 parents 2dcbb17 + 9cb314d commit b85eff2

File tree

5 files changed

+68
-22
lines changed

5 files changed

+68
-22
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
2020

2121
- Fixes opensearchtransport ignores request context cancellation when `retryBackoff` is configured ([#540](https://github.com/opensearch-project/opensearch-go/pull/540))
2222
- Fixes opensearchtransport sleeps unexpectedly after the last retry ([#540](https://github.com/opensearch-project/opensearch-go/pull/540))
23+
- Fixes empty request body on retry with compression enabled ([#543](https://github.com/opensearch-project/opensearch-go/pull/543))
2324

2425
### Security
2526

2627
### Dependencies
27-
- Bump `github.com/aws/aws-sdk-go` from 1.51.21 to 1.52.3 ([#534](https://github.com/opensearch-project/opensearch-go/pull/534), [#537](https://github.com/opensearch-project/opensearch-go/pull/537), [#538](https://github.com/opensearch-project/opensearch-go/pull/538))
28+
- Bump `github.com/aws/aws-sdk-go` from 1.51.21 to 1.53.1 ([#534](https://github.com/opensearch-project/opensearch-go/pull/534), [#537](https://github.com/opensearch-project/opensearch-go/pull/537), [#538](https://github.com/opensearch-project/opensearch-go/pull/538), [#545](https://github.com/opensearch-project/opensearch-go/pull/545))
2829
- Bump `github.com/wI2L/jsondiff` from 0.5.1 to 0.5.2 ([#535](https://github.com/opensearch-project/opensearch-go/pull/535))
30+
- Bump `github.com/aws/aws-sdk-go-v2/config` from 1.27.11 to 1.27.13 ([#546](https://github.com/opensearch-project/opensearch-go/pull/546))
2931

3032
## [4.0.0]
3133

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ module github.com/opensearch-project/opensearch-go/v4
33
go 1.21
44

55
require (
6-
github.com/aws/aws-sdk-go v1.52.3
6+
github.com/aws/aws-sdk-go v1.53.1
77
github.com/aws/aws-sdk-go-v2 v1.26.1
8-
github.com/aws/aws-sdk-go-v2/config v1.27.11
8+
github.com/aws/aws-sdk-go-v2/config v1.27.13
99
github.com/stretchr/testify v1.9.0
1010
github.com/wI2L/jsondiff v0.5.2
1111
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
1212
)
1313

1414
require (
15-
github.com/aws/aws-sdk-go-v2/credentials v1.17.11 // indirect
15+
github.com/aws/aws-sdk-go-v2/credentials v1.17.13 // indirect
1616
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 // indirect
1717
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect
1818
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect
1919
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
2020
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
2121
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect
22-
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 // indirect
23-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 // indirect
24-
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 // indirect
22+
github.com/aws/aws-sdk-go-v2/service/sso v1.20.6 // indirect
23+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.0 // indirect
24+
github.com/aws/aws-sdk-go-v2/service/sts v1.28.7 // indirect
2525
github.com/aws/smithy-go v1.20.2 // indirect
2626
github.com/davecgh/go-spew v1.1.1 // indirect
2727
github.com/jmespath/go-jmespath v0.4.0 // indirect

go.sum

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
github.com/aws/aws-sdk-go v1.52.3 h1:BNPJmHOXNoM/iBWJKrvaQvJOweRcp3KLpzdb65CfQwU=
2-
github.com/aws/aws-sdk-go v1.52.3/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
1+
github.com/aws/aws-sdk-go v1.53.1 h1:15/i0m9rE8r1q3P4ooHCfZTJtkxwG2Dwqp9JhPaVbs0=
2+
github.com/aws/aws-sdk-go v1.53.1/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
33
github.com/aws/aws-sdk-go-v2 v1.26.1 h1:5554eUqIYVWpU0YmeeYZ0wU64H2VLBs8TlhRB2L+EkA=
44
github.com/aws/aws-sdk-go-v2 v1.26.1/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM=
5-
github.com/aws/aws-sdk-go-v2/config v1.27.11 h1:f47rANd2LQEYHda2ddSCKYId18/8BhSRM4BULGmfgNA=
6-
github.com/aws/aws-sdk-go-v2/config v1.27.11/go.mod h1:SMsV78RIOYdve1vf36z8LmnszlRWkwMQtomCAI0/mIE=
7-
github.com/aws/aws-sdk-go-v2/credentials v1.17.11 h1:YuIB1dJNf1Re822rriUOTxopaHHvIq0l/pX3fwO+Tzs=
8-
github.com/aws/aws-sdk-go-v2/credentials v1.17.11/go.mod h1:AQtFPsDH9bI2O+71anW6EKL+NcD7LG3dpKGMV4SShgo=
5+
github.com/aws/aws-sdk-go-v2/config v1.27.13 h1:WbKW8hOzrWoOA/+35S5okqO/2Ap8hkkFUzoW8Hzq24A=
6+
github.com/aws/aws-sdk-go-v2/config v1.27.13/go.mod h1:XLiyiTMnguytjRER7u5RIkhIqS8Nyz41SwAWb4xEjxs=
7+
github.com/aws/aws-sdk-go-v2/credentials v1.17.13 h1:XDCJDzk/u5cN7Aple7D/MiAhx1Rjo/0nueJ0La8mRuE=
8+
github.com/aws/aws-sdk-go-v2/credentials v1.17.13/go.mod h1:FMNcjQrmuBYvOTZDtOLCIu0esmxjF7RuA/89iSXWzQI=
99
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 h1:FVJ0r5XTHSmIHJV6KuDmdYhEpvlHpiSd38RQWhut5J4=
1010
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1/go.mod h1:zusuAeqezXzAB24LGuzuekqMAEgWkVYukBec3kr3jUg=
1111
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 h1:aw39xVGeRWlWx9EzGVnhOR4yOjQDHPQ6o6NmBlscyQg=
@@ -18,12 +18,12 @@ github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 h1:Ji0DY1x
1818
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2/go.mod h1:5CsjAbs3NlGQyZNFACh+zztPDI7fU6eW9QsxjfnuBKg=
1919
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 h1:ogRAwT1/gxJBcSWDMZlgyFUM962F51A5CRhDLbxLdmo=
2020
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7/go.mod h1:YCsIZhXfRPLFFCl5xxY+1T9RKzOKjCut+28JSX2DnAk=
21-
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 h1:vN8hEbpRnL7+Hopy9dzmRle1xmDc7o8tmY0klsr175w=
22-
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5/go.mod h1:qGzynb/msuZIE8I75DVRCUXw3o3ZyBmUvMwQ2t/BrGM=
23-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 h1:Jux+gDDyi1Lruk+KHF91tK2KCuY61kzoCpvtvJJBtOE=
24-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4/go.mod h1:mUYPBhaF2lGiukDEjJX2BLRRKTmoUSitGDUgM4tRxak=
25-
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 h1:cwIxeBttqPN3qkaAjcEcsh8NYr8n2HZPkcKgPAi1phU=
26-
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6/go.mod h1:FZf1/nKNEkHdGGJP/cI2MoIMquumuRK6ol3QQJNDxmw=
21+
github.com/aws/aws-sdk-go-v2/service/sso v1.20.6 h1:o5cTaeunSpfXiLTIBx5xo2enQmiChtu1IBbzXnfU9Hs=
22+
github.com/aws/aws-sdk-go-v2/service/sso v1.20.6/go.mod h1:qGzynb/msuZIE8I75DVRCUXw3o3ZyBmUvMwQ2t/BrGM=
23+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.0 h1:Qe0r0lVURDDeBQJ4yP+BOrJkvkiCo/3FH/t+wY11dmw=
24+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.0/go.mod h1:mUYPBhaF2lGiukDEjJX2BLRRKTmoUSitGDUgM4tRxak=
25+
github.com/aws/aws-sdk-go-v2/service/sts v1.28.7 h1:et3Ta53gotFR4ERLXXHIHl/Uuk1qYpP5uU7cvNql8ns=
26+
github.com/aws/aws-sdk-go-v2/service/sts v1.28.7/go.mod h1:FZf1/nKNEkHdGGJP/cI2MoIMquumuRK6ol3QQJNDxmw=
2727
github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q=
2828
github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E=
2929
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

opensearchtransport/opensearchtransport.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ func (c *Client) Perform(req *http.Request) (*http.Response, error) {
245245
}
246246

247247
req.GetBody = func() (io.ReadCloser, error) {
248-
return io.NopCloser(buf), nil
248+
// We have to return a new reader each time so that retries don't read from an already-consumed body.
249+
reader := bytes.NewReader(buf.Bytes())
250+
return io.NopCloser(reader), nil
249251
}
250252
//nolint:errcheck // error is always nil
251253
req.Body, _ = req.GetBody()
@@ -258,8 +260,9 @@ func (c *Client) Perform(req *http.Request) (*http.Response, error) {
258260
//nolint:errcheck // ignored as this is only for logging
259261
buf.ReadFrom(req.Body)
260262
req.GetBody = func() (io.ReadCloser, error) {
261-
r := buf
262-
return io.NopCloser(&r), nil
263+
// Return a new reader each time
264+
reader := bytes.NewReader(buf.Bytes())
265+
return io.NopCloser(reader), nil
263266
}
264267
//nolint:errcheck // error is always nil
265268
req.Body, _ = req.GetBody()

opensearchtransport/opensearchtransport_internal_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,47 @@ func TestTransportPerformRetries(t *testing.T) {
691691
}
692692
})
693693

694+
t.Run("Reset request body during retry with request body compression", func(t *testing.T) {
695+
var bodies []string
696+
u, _ := url.Parse("https://foo.com/bar")
697+
tp, _ := New(
698+
Config{
699+
URLs: []*url.URL{u},
700+
CompressRequestBody: true,
701+
Transport: &mockTransp{
702+
RoundTripFunc: func(req *http.Request) (*http.Response, error) {
703+
body, err := io.ReadAll(req.Body)
704+
if err != nil {
705+
panic(err)
706+
}
707+
bodies = append(bodies, string(body))
708+
return &http.Response{Status: "MOCK", StatusCode: http.StatusBadGateway}, nil
709+
},
710+
},
711+
},
712+
)
713+
714+
foobar := "FOOBAR"
715+
foobarGzipped := "\x1f\x8b\b\x00\x00\x00\x00\x00\x00\xffr\xf3\xf7wr\f\x02\x04\x00\x00\xff\xff\x13\xd8\x0en\x06\x00\x00\x00"
716+
717+
req, _ := http.NewRequest(http.MethodPost, "/abc", strings.NewReader(foobar))
718+
//nolint:bodyclose // Mock response does not have a body to close
719+
res, err := tp.Perform(req)
720+
if err != nil {
721+
t.Fatalf("Unexpected error: %s", err)
722+
}
723+
_ = res
724+
725+
if n := len(bodies); n != 4 {
726+
t.Fatalf("expected 4 requests, got %d", n)
727+
}
728+
for i, body := range bodies {
729+
if body != foobarGzipped {
730+
t.Fatalf("request %d body: expected %q, got %q", i, foobarGzipped, body)
731+
}
732+
}
733+
})
734+
694735
t.Run("Don't retry request on regular error", func(t *testing.T) {
695736
var i int
696737

0 commit comments

Comments
 (0)