Skip to content

fix: Prevent a NaN or infinite metric value from discarding all events in a flush - #498

Merged
keelerm84 merged 1 commit into
launchdarkly:mainfrom
pcbeingused333:fix/track-nonfinite-metric
Nov 20, 2026
Merged

keelerm84 merged 1 commit into
launchdarkly:mainfrom
pcbeingused333:fix/track-nonfinite-metric

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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 (specs run on Ruby 3.3 only)

Related issues

No issue in this repository. The same failure mode is addressed for the Go SDK in launchdarkly/go-sdk-events#69.

Describe the solution you've provided

LDClient#track with a NaN or ±Infinity metric value makes the whole event batch fail to serialize. CustomEvent#metric_value goes straight into events_out.to_json, which raises JSON::GeneratorError for non-finite floats. The error is rescued and logged inside the flush worker, but trigger_flush has already handed the payload over and cleared the outbox, so every other event in that flush (and the summary) is lost.

EventProcessor#record_custom_event now logs a warning and drops only that custom event when metric_value is a non-finite Float. Other events are untouched; data is not inspected.

Three specs in spec/events_spec.rb (NaN, +Infinity, -Infinity) record a healthy custom event plus a bad one and assert that only the healthy one is delivered. They fail without the change and pass with it.

Reproduction:

bundle exec rspec spec/events_spec.rb -e "non-finite metric value"

Describe alternatives you've considered

  • Sending the event without metricValue: keeps the event but silently reports a different measurement.
  • Rescuing the serialization error per event in the formatter: a larger change in the hot path, for a value that is never valid.

Additional context

This change was prepared with the assistance of an AI coding agent (Claude) and has not been reviewed line by line by a human prior to submission.


Note

Overview
Custom events with a NaN or ±Infinity metricValue no longer break an entire flush batch. EventProcessor#record_custom_event now rejects non-finite Float metrics with a warning and skips enqueueing that event only.

Specs cover NaN, +Infinity, and -Infinity: a valid custom event in the same flush still ships.

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

…ing the batch

NaN and +/-Infinity metric values made JSON serialization raise, losing every event in the same flush.

Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 13, 2026 08:11
@keelerm84 keelerm84 changed the title fix: drop custom events with non-finite metric values instead of failing the batch fix: Prevent a NaN or infinite metric value from discarding all events in a flush Nov 20, 2026
@keelerm84
keelerm84 merged commit 2b0f4ef into launchdarkly:main Nov 20, 2026
12 checks passed
@keelerm84

Copy link
Copy Markdown
Member

@pcbeingused333 thank you for contributing this fix!

keelerm84 pushed a commit that referenced this pull request Nov 20, 2026
🤖 I have created a release *beep* *boop*
---


##
[8.20.1](8.20.0...8.20.1)
(2026-11-20)


### Bug Fixes

* Prevent a NaN or infinite metric value from discarding all events in a
flush
([#498](#498))
([2b0f4ef](2b0f4ef))
* Restart the stream when a delete event has a version that is not an
integer
([#501](#501))
([d060827](d060827))
* Signal readiness when selectorless initializers are exhausted
([#499](#499))
([22fda02](22fda02))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.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.

2 participants