Repository navigation
fix: Drop trackMetric events with a NaN or infinite metric value - #287
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Requirements
LDClientEventTestrun 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#trackMetricpassesmetricValueto the event processor without checking it. ForNaNor±Infinity, Gson throws inEventOutputFormatterwhen the value is written. The exception is caught around the whole flush inDefaultEventProcessor, so the other events and the summaries in that batch are not delivered either.trackMetricnow 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
trackMetricWithNonFiniteValueDoesNotSendEventcovers 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
trackMetricnow validates the metricdoubleafter 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.