fix(ci-visibility): fix race condition in agent-proxy exporter#7375
Merged
fix(ci-visibility): fix race condition in agent-proxy exporter#7375
Conversation
Contributor
Overall package sizeSelf size: 4.46 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 2.0.3 | 76.87 kB | 808.03 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7375 +/- ##
==========================================
- Coverage 86.16% 86.16% -0.01%
==========================================
Files 515 515
Lines 22246 22245 -1
==========================================
- Hits 19169 19168 -1
Misses 3077 3077 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
juan-fernandez
previously approved these changes
Jan 29, 2026
Fixes a race condition in AgentProxyCiVisibilityExporter where `_isGzipCompatible` and `evpProxyPrefix` could be read before being set, causing intermittent test failures in CI. The race condition was amplified by commit 6eed53f which added caching to fetchAgentInfo. When the cache is hit, the callback runs via process.nextTick (extremely fast), making the timing window between promise resolution and property assignment visible. Production code fix: - Move `this._isGzipCompatible = isGzipCompatible` to execute before `this._resolveCanUseCiVisProtocol()` in the callback - This ensures the property is set before tests (or production code) can read it after awaiting `_canUseCiVisProtocolPromise` - Matches the pattern in AgentlessCiVisibilityExporter Test cleanup fix: - Add `nock.cleanAll()` to beforeEach hook to prevent HTTP mock state leakage between tests - Without cleanup, nock interceptors from previous tests could interfere with subsequent tests - Follows the pattern in exporter.spec.js and other test files Fixes 4 flaky tests: - _isGzipCompatible (v4+ and v3 version checks) - evpProxyPrefix (v2 and v4 prefix assignments)
7415ce7 to
3e692b1
Compare
juan-fernandez
approved these changes
Jan 29, 2026
Collaborator
juan-fernandez
left a comment
There was a problem hiding this comment.
good catch! Thanks
dd-octo-sts bot
pushed a commit
that referenced
this pull request
Jan 29, 2026
Fixes a race condition in AgentProxyCiVisibilityExporter where `_isGzipCompatible` and `evpProxyPrefix` could be read before being set, causing intermittent test failures in CI. The race condition was amplified by commit 6eed53f which added caching to fetchAgentInfo. When the cache is hit, the callback runs via process.nextTick (extremely fast), making the timing window between promise resolution and property assignment visible. Production code fix: - Move `this._isGzipCompatible = isGzipCompatible` to execute before `this._resolveCanUseCiVisProtocol()` in the callback - This ensures the property is set before tests (or production code) can read it after awaiting `_canUseCiVisProtocolPromise` - Matches the pattern in AgentlessCiVisibilityExporter Test cleanup fix: - Add `nock.cleanAll()` to beforeEach hook to prevent HTTP mock state leakage between tests - Without cleanup, nock interceptors from previous tests could interfere with subsequent tests - Follows the pattern in exporter.spec.js and other test files Fixes 4 flaky tests: - _isGzipCompatible (v4+ and v3 version checks) - evpProxyPrefix (v2 and v4 prefix assignments)
Merged
BridgeAR
pushed a commit
that referenced
this pull request
Jan 30, 2026
Fixes a race condition in AgentProxyCiVisibilityExporter where `_isGzipCompatible` and `evpProxyPrefix` could be read before being set, causing intermittent test failures in CI. The race condition was amplified by commit 6eed53f which added caching to fetchAgentInfo. When the cache is hit, the callback runs via process.nextTick (extremely fast), making the timing window between promise resolution and property assignment visible. Production code fix: - Move `this._isGzipCompatible = isGzipCompatible` to execute before `this._resolveCanUseCiVisProtocol()` in the callback - This ensures the property is set before tests (or production code) can read it after awaiting `_canUseCiVisProtocolPromise` - Matches the pattern in AgentlessCiVisibilityExporter Test cleanup fix: - Add `nock.cleanAll()` to beforeEach hook to prevent HTTP mock state leakage between tests - Without cleanup, nock interceptors from previous tests could interfere with subsequent tests - Follows the pattern in exporter.spec.js and other test files Fixes 4 flaky tests: - _isGzipCompatible (v4+ and v3 version checks) - evpProxyPrefix (v2 and v4 prefix assignments)
BridgeAR
pushed a commit
that referenced
this pull request
Feb 22, 2026
Fixes a race condition in AgentProxyCiVisibilityExporter where `_isGzipCompatible` and `evpProxyPrefix` could be read before being set, causing intermittent test failures in CI. The race condition was amplified by commit 6eed53f which added caching to fetchAgentInfo. When the cache is hit, the callback runs via process.nextTick (extremely fast), making the timing window between promise resolution and property assignment visible. Production code fix: - Move `this._isGzipCompatible = isGzipCompatible` to execute before `this._resolveCanUseCiVisProtocol()` in the callback - This ensures the property is set before tests (or production code) can read it after awaiting `_canUseCiVisProtocolPromise` - Matches the pattern in AgentlessCiVisibilityExporter Test cleanup fix: - Add `nock.cleanAll()` to beforeEach hook to prevent HTTP mock state leakage between tests - Without cleanup, nock interceptors from previous tests could interfere with subsequent tests - Follows the pattern in exporter.spec.js and other test files Fixes 4 flaky tests: - _isGzipCompatible (v4+ and v3 version checks) - evpProxyPrefix (v2 and v4 prefix assignments)
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.

What does this PR do?
Fixes a race condition in
AgentProxyCiVisibilityExporterwhere_isGzipCompatibleandevpProxyPrefixcould be read before being set, causing intermittent test failures in CI. Also adds proper test cleanup to prevent nock mock state leakage.Motivation
Four tests in the agent-proxy test suite were failing intermittently in CI:
_isGzipCompatible- should set to true if newest version is v4 or newer_isGzipCompatible- should set to false if newest version is v3 or olderevpProxyPrefix- should set to v2 if newest version is v3evpProxyPrefix- should set to v4 if newest version is v4Root Cause: A race condition in the production code, amplified by commit 6eed53f which added caching to
fetchAgentInfo. When the cache is hit, the callback runs viaprocess.nextTick(extremely fast), making the timing window between promise resolution and property assignment visible.The Race Condition:
Fixes Applied:
Production code fix (
packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js):this._isGzipCompatibledirectly and early in thefetchAgentInfocallback (line 50)this._resolveCanUseCiVisProtocol()resolves the promise_canUseCiVisProtocolPromiseAgentlessCiVisibilityExporterwhich sets_isGzipCompatiblesynchronously in the constructorTest cleanup fix (
packages/dd-trace/test/ci-visibility/exporters/agent-proxy/agent-proxy.spec.js):nock.cleanAll()tobeforeEachhook to prevent HTTP mock state leakage between testsexporter.spec.jsand other test filesThe flakiness only manifested in CI due to parallel test execution, process reuse, and timing variations that don't occur in local development.