Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changefeedccl: repopulate request body for webhook sink retries #119326

Merged

Conversation

rharding6373
Copy link
Collaborator

@rharding6373 rharding6373 commented Feb 17, 2024

The webhook sink reuses an http request for retries. However, the http library consumes the request body, so retries may result in an error due to a non-zero content length but zero length body. This change re-initializes the http request body on every request so that it will have the right contents on every retry.

Epic: none
Fixes: #118485

Release note (bug fix): Fixes a bug in the webhook sink where the http request body may not be initialized on retries, resulting in the error "http: ContentLength=... with Body length 0".

@rharding6373 rharding6373 requested a review from a team as a code owner February 17, 2024 00:28
@rharding6373 rharding6373 requested review from jayshrivastava and removed request for a team February 17, 2024 00:28
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator Author

@rharding6373 rharding6373 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @jayshrivastava)


pkg/ccl/changefeedccl/sink_webhook_test.go line 735 at r1 (raw file):

	}{
		key:   changefeedbase.OptWebhookSinkConfig,
		value: `{"Retry":{"Backoff": "1s", "Max": "2"}}`})

Without the code change, this test doesn't reliably fail unless the Backoff is ~60s (which requires a change to sink options to have a retry max backoff of >60s). In the debugger, I see the error in the http library but it seems like it takes time to be consumed and propagated and I don't fully understand why yet. I don't think we want to adjust the retry max backoff or expose it as an option just to get this test working well. Since this change has been tested manually and with an adjusted backoff, I'm confident that it fixes the problem, but I'm sad that the unit test isn't consistent. Thoughts?

Copy link
Contributor

@jayshrivastava jayshrivastava left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just left one nit.

key string
value string
}{
key: changefeedbase.OptWebhookSinkConfig,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the test take longer to run with these options? If so, using 0 backoff would be better.

@rharding6373 rharding6373 added backport-23.1.x Flags PRs that need to be backported to 23.1 backport-23.2.x Flags PRs that need to be backported to 23.2. labels Feb 21, 2024
Copy link
Collaborator Author

@rharding6373 rharding6373 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TFTR!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @jayshrivastava)


pkg/ccl/changefeedccl/sink_webhook_test.go line 734 at r1 (raw file):

Previously, jayshrivastava (Jayant) wrote…

Does the test take longer to run with these options? If so, using 0 backoff would be better.

I don't think it will repro with 0 backoff, but I did reduce it so that the test can run in ~1s. I also added a comment to explain the repro issues we discussed.

The webhook sink reuses an http request for retries. However, the http
library consumes the request body, so retries may result in an error due
to a non-zero content length but zero length body. This change
re-initializes the http request body on every request so that it will
have the right contents on every retry.

Epic: none
Fixes: cockroachdb#118485

Release note (bug fix): Fixes a bug in the webhook sink where the
http request body may not be initialized on retries, resulting in the
error "http: ContentLength=... with Body length 0".
@rharding6373
Copy link
Collaborator Author

TFTR!

bors r=jayshrivastava

@craig
Copy link
Contributor

craig bot commented Feb 22, 2024

Build succeeded:

@craig craig bot merged commit a85e6e2 into cockroachdb:master Feb 22, 2024
8 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-23.1.x Flags PRs that need to be backported to 23.1 backport-23.2.x Flags PRs that need to be backported to 23.2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

changefeedccl: Incorrect retry logic in webhook sink
3 participants