Skip to content

fix: delay client removal in contract test service to mitigate flaky FDv2 test (SDK-2050)#1200

Closed
joker23 wants to merge 2 commits intomainfrom
devin/1773866180-fix-flaky-fdv2-contract-test
Closed

fix: delay client removal in contract test service to mitigate flaky FDv2 test (SDK-2050)#1200
joker23 wants to merge 2 commits intomainfrom
devin/1773866180-fix-flaky-fdv2-contract-test

Conversation

@joker23
Copy link
Contributor

@joker23 joker23 commented Mar 18, 2026

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

Describe the solution you've provided

The streaming/fdv2/permanent fallback to secondary synchronizer contract test fails intermittently with a 404 on POST /clients/:id.

Root cause: The preceding DisconnectsOnGoodbye test uses testify's assert.Never, which spawns goroutines to poll a condition. These goroutines can outlive the Never call—when the test finishes and cleanup sends DELETE /clients/:id, the client is immediately removed from the pool. A stale goroutine then calls EvaluateFlag on the now-missing client, gets a 404, and panics via require.NoError, crashing the next test. The stack trace confirms this (assert.Never.func1 → DisconnectsOnGoodbye.checkForUpdatedValue.func1).

Fix: Delay removal of the client from the ClientPool by 1 second after closing it. Since InMemoryFeatureStore.close() is a no-op, the closed client can still serve stale flag evaluation requests with valid cached data, preventing the 404.

Describe alternatives you've considered

  1. Suppress the flaky test in testharness-suppressions-fdv2.txt — loses coverage.
  2. Fix the Go test harness to avoid goroutine leaks from assert.Never — not in scope for this repo.
  3. Return a non-error response for deleted clients — would mask real issues.

Additional context

Important

For reviewers: The 1-second delay is a heuristic chosen to exceed the assert.Never parameters in the harness (waitFor=100ms, tick=20ms). The closed client still has its in-memory store intact, so variation() returns real data. However, other subsystems (event processor, update processor) are closed—this is safe because the stale goroutines only call EvaluateFlag, which only needs the feature store.

Note that similar failures were observed before the got removal (Mar 12–13), suggesting this is a pre-existing race condition in the FDv2 test suite rather than a regression from PR #1188.

Link to Devin session: https://app.devin.ai/sessions/6d2f3eb1ad234bff9516ca5a5ef2c6f0
Requested by: @joker23


Note

Low Risk
Low risk: change is isolated to the contract test service cleanup path and only affects when a closed client is removed from the in-memory ClientPool.

Overview
Mitigates a flaky contract-test race by delaying ClientPool removal of a client for 1s after DELETE /clients/:id, instead of removing it immediately.

The service still closes the client right away, but keeps the entry briefly so late test-harness requests don’t hit a transient 404 during teardown.

Written by Cursor Bugbot for commit c5bae6d. This will update automatically on new commits. Configure here.


Open with Devin

…ondition

The DisconnectsOnGoodbye FDv2 test uses assert.Never which spawns
goroutines that can outlive the test. When the test cleanup deletes
the client, stale goroutines may still try to evaluate flags on it,
resulting in a 404 that crashes the next test.

By delaying removal from the pool for 1 second after closing, the
closed client can still serve requests (InMemoryFeatureStore.close()
is a no-op) while stale goroutines complete.

Co-Authored-By: Steven Zhang <szhang@launchdarkly.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@devin-ai-integration devin-ai-integration bot added the devin-pr PRs created by Devin AI label Mar 18, 2026
@github-actions
Copy link
Contributor

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 25566 bytes
Compressed size limit: 26000
Uncompressed size: 125383 bytes

@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

@launchdarkly/browser size report
This is the brotli compressed size of the ESM build.
Compressed size: 172365 bytes
Compressed size limit: 200000
Uncompressed size: 802275 bytes

@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 24546 bytes
Compressed size limit: 25000
Uncompressed size: 85156 bytes

@joker23
Copy link
Contributor Author

joker23 commented Mar 18, 2026

@cursor review

@github-actions
Copy link
Contributor

@launchdarkly/js-client-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 22203 bytes
Compressed size limit: 24000
Uncompressed size: 115238 bytes

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@devin-ai-integration
Copy link
Contributor

@cursor review

@joker23 joker23 marked this pull request as ready for review March 18, 2026 20:52
@joker23 joker23 requested a review from a team as a code owner March 18, 2026 20:52
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@joker23 joker23 marked this pull request as draft March 19, 2026 20:32
@joker23
Copy link
Contributor Author

joker23 commented Mar 19, 2026

I'll put in a fix in test-harness... will close once we can verify the fix in test harness works

@joker23
Copy link
Contributor Author

joker23 commented Mar 19, 2026

fixed upstream

@joker23 joker23 closed this Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devin-pr PRs created by Devin AI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant