Skip to content

Commit e12c195

Browse files
authored
fix(ci-visibility): fix race condition in agent-proxy exporter (#7375)
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)
1 parent a2ff667 commit e12c195

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class AgentProxyCiVisibilityExporter extends CiVisibilityExporter {
4747
this._isInitialized = true
4848
let latestEvpProxyVersion = getLatestEvpProxyVersion(err, agentInfo)
4949
const isEvpCompatible = latestEvpProxyVersion >= 2
50-
const isGzipCompatible = latestEvpProxyVersion >= 4
50+
this._isGzipCompatible = latestEvpProxyVersion >= 4
5151

5252
// v3 does not work well citestcycle, so we downgrade to v2
5353
if (latestEvpProxyVersion === 3) {
@@ -92,7 +92,6 @@ class AgentProxyCiVisibilityExporter extends CiVisibilityExporter {
9292
this._resolveCanUseCiVisProtocol(isEvpCompatible)
9393
this.exportUncodedTraces()
9494
this.exportUncodedCoverages()
95-
this._isGzipCompatible = isGzipCompatible
9695
})
9796
}
9897

packages/dd-trace/test/ci-visibility/exporters/agent-proxy/agent-proxy.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const { clearCache } = require('../../../../src/agent/info')
1919
describe('AgentProxyCiVisibilityExporter', () => {
2020
beforeEach(() => {
2121
clearCache()
22+
nock.cleanAll()
2223
})
2324

2425
const flushInterval = 50

0 commit comments

Comments
 (0)