Skip to content

Reset request body on retry#774

Merged
n3wscott merged 1 commit intocloudevents:mainfrom
embano1:issue-773
Jun 10, 2022
Merged

Reset request body on retry#774
n3wscott merged 1 commit intocloudevents:mainfrom
embano1:issue-773

Conversation

@embano1
Copy link
Copy Markdown
Member

@embano1 embano1 commented Jun 9, 2022

Fixes a bug where requests with a body (event) are not always retried due to the underlying net/http throwing *url.Error because of body and content-length mismatch (body is empty and not reset upon retry). See #773 for details.

The tests did not catch this as they were not doing behaving as a real HTTP server (just mocking RoundTripper) and also not carrying an event body (which would not trigger this behavior).

  • Changed retry tests to use a network connection and HTTP (test) server
  • Reset body (if not nil) during retries
  • Set GetBody func only if it is not already set (the sdk already does this currently)

Closes: #773
Signed-off-by: Michael Gasch mgasch@vmware.com

@embano1 embano1 changed the title fix: Reset request body on retry Reset request body on retry Jun 9, 2022
Closes: cloudevents#773
Signed-off-by: Michael Gasch <mgasch@vmware.com>
@embano1
Copy link
Copy Markdown
Member Author

embano1 commented Jun 9, 2022

Linter workflow seems broken.

Running locally only throws a small (existing) nit:

golangci-lint run
protocol/http/result_test.go:95:5: S1038: should use t.Errorf(...) instead of t.Error(fmt.Sprintf(...)) (gosimple)
                                t.Error(fmt.Sprintf("%v, expected result to be IsUndelivered == %t, got %t", tc.name, tc.want, got))

@n3wscott
Copy link
Copy Markdown
Member

Thank you so much @embano1 !! Both for the detailed bug report and the follow-up fix. I will cherry-pick this into the current release as a bug fix and we will get this out. 🙏 🙏 🙏

@n3wscott n3wscott merged commit 249465f into cloudevents:main Jun 10, 2022
@embano1 embano1 deleted the issue-773 branch June 10, 2022 15:01
n3wscott added a commit that referenced this pull request Jun 10, 2022
Closes: #773
Signed-off-by: Michael Gasch <mgasch@vmware.com>

Co-authored-by: Michael Gasch <mgasch@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

req.Body not reset in doWithRetry

2 participants