Repository navigation
fix: Prevent dropped event batches when reading the response body fails - #516
Merged
keelerm84 merged 3 commits intoDec 4, 2026
Merged
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit de52154. Configure here.
keelerm84
approved these changes
Dec 4, 2026
Member
|
Thank you again @pcbeingused33! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

BEGIN_COMMIT_OVERRIDE
fix: Prevent dropped event batches when reading the response body fails
fix: Prevent a failed event delivery from causing the next batch's first attempt to fail
END_COMMIT_OVERRIDE
fix: Prevent a failed event delivery from causing the next batch's first attempt to fail
Requirements
Related issues
No issue in this repository. This is in the same flush path as #498: today a failed body read escapes the retry loop and the batch is dropped as an "Unexpected error in event processor".
Describe the solution you've provided
The event sender reads the response body after leaving the retry handler. If a server returns a 503 and the body read times out, the exception aborts delivery before the pending batch can be retried.
Read the status as soon as the request returns, then drain the body in a separate rescue. A failed body read no longer discards the status: a 2xx still succeeds, a 401 or 403 still shuts delivery down, and a 5xx still retries once with the same payload ID. On a failed read the client closes the connection, so the next request does not reuse a half-read connection.
The event sender and event processor specs ran on Ruby 4.0.9. Before the fix, the new regression failed with an uncaught timeout. All 67 examples passed with the fix. RuboCop reported zero offenses in the changed files.
Additional context
AI assistance was used to prepare the patch and regression test.
Note
Overview
Fixes event delivery when the HTTP response status is valid but draining the response body fails (e.g. timeout on
flush). Previously a body-read exception could bypass retry logic and drop the batch.The sender now records status before draining the body, wraps body drain in its own rescue, and closes the HTTP client on send errors or failed drains so keep-alive connections are not reused half-read. 2xx still counts as success (including server
Date), 401/403 still trigger shutdown, and recoverable 5xx still get one retry with the same payload ID.Adds regression specs for 503 retry, double-failure, 2xx success, 401 shutdown, and diagnostic sends when
flushraises.Reviewed by Cursor Bugbot for commit a1a27a9. Bugbot is set up for automated code reviews on this repo. Configure here.