Skip to content

fix: Drop trackMetric events with a NaN or infinite metric value - #287

Open
pcbeingused333 wants to merge 1 commit into
launchdarkly:mainfrom
pcbeingused333:fix/track-metric-non-finite
Open

pcbeingused333 wants to merge 1 commit into
launchdarkly:mainfrom
pcbeingused333:fix/track-metric-non-finite

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 27, 2026 •

Copy link
Copy Markdown

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 (LDClientEventTest run on JDK 17 only)

Related issues

No issue in this repository. Same failure mode as launchdarkly/go-server-sdk#520 and launchdarkly/ruby-server-sdk#498.

Describe the solution you've provided

LDClient#trackMetric passes metricValue to the event processor without checking it. For NaN or ±Infinity, Gson throws in EventOutputFormatter when the value is written. The exception is caught around the whole flush in DefaultEventProcessor, so the other events and the summaries in that batch are not delivered either.

trackMetric now checks the value after the existing context checks. For a non-finite value it logs a warning with the event name and does not record the event. Finite values are unchanged.

The added test trackMetricWithNonFiniteValueDoesNotSendEvent covers all three values. It fails without the change and passes with it.

Describe alternatives you've considered

Checking in EventOutputFormatter (shared internal library). That would also protect the payload, but the Go SDK fix put the check in the SDK, where it can warn at the call site.

Additional context

This change was prepared with AI assistance (Claude Code).


Note

Overview
trackMetric now validates the metric double after context checks. NaN and ±Infinity trigger a warning (including the event name) and the event is not recorded, matching fixes in other server SDKs.

Without this guard, non-finite values could break JSON serialization during flush and prevent other events in the same batch from being delivered.

A unit test asserts that all three non-finite values produce no custom events in the test sink.

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

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 27, 2026 06:55

This branch has not been deployed

No deployments
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.

1 participant