-
Notifications
You must be signed in to change notification settings - Fork 364
fix(ci-visibility): fix race condition in agent-proxy exporter #7375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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:
|
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
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch! Thanks
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)
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)

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.