Skip to content

fix: Prevent dropped event batches when reading the response body fails - #516

Merged
keelerm84 merged 3 commits into
launchdarkly:mainfrom
pcbeingused33:fix/event-response-read-retry
Dec 4, 2026
Merged

keelerm84 merged 3 commits into
launchdarkly:mainfrom
pcbeingused33:fix/event-response-read-retry

Conversation

@pcbeingused33

@pcbeingused33 pcbeingused33 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

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 flush raises.

Reviewed by Cursor Bugbot for commit a1a27a9. Bugbot is set up for automated code reviews on this repo. Configure here.

@pcbeingused33
pcbeingused33 requested a review from a team as a code owner December 1, 2026 09:35

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit de52154. Configure here.

Comment thread lib/ldclient-rb/impl/event_sender.rb Resolved
@keelerm84 keelerm84 changed the title fix: retry event delivery after response body read failures fix: Prevent dropped event batches when reading the response body fails Dec 4, 2026
@keelerm84
keelerm84 merged commit 0bece02 into launchdarkly:main Dec 4, 2026
8 checks passed
@keelerm84

Copy link
Copy Markdown
Member

Thank you again @pcbeingused33!

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.

2 participants