Unverified Commit 3c9d1ca7 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

test: avoid OpenTelemetry collector socket reuse (#98632)

### What?

Prevent the OpenTelemetry instrumentation e2e collector from losing span
exports when an exporter reuses an idle localhost connection. Add
focused coverage for the collector's connection behavior.

### Why?

Keeping the collector listener alive for each application's full
lifetime removed the earlier close-and-rebind gap, but did not eliminate
every socket failure. Node's HTTP server could still time out an idle
keep-alive socket retained by the exporter's Undici pool. A later export
could race that closure, lose spans with `UND_ERR_SOCKET` or
`ECONNRESET`, and leave otherwise unrelated trace assertions with
incomplete trees.

The canary.28 failure was investigated separately and is not this
mechanism: it occurred in the release-enabled Rspack matrix when a
custom server exited during startup. This change is limited to the
residual non-Rspack collector race and does not alter Rspack coverage or
release snapshots.

### How?

Successful collector exports explicitly close their HTTP connection.
Each export therefore uses a fresh local connection instead of retaining
a socket that the server may reclaim while idle. The regression test
asserts this response contract directly, avoiding timing-dependent
coverage of the race.

### Verification

- Node 20.9.0, webpack dev, React 18.3.1: 5 consecutive focused runs, 55
tests passed per run
- Node 20.9.0, webpack start, React 18.3.1: 99 passed, 13 existing skips
- `pnpm test-types`
- Prettier and ESLint on changed files

<!-- NEXT_JS_LLM -->


<!-- fleet e4b8ed15-4a06-4727-a634-fddcc27c11fc -->
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent 8a53b57d
...@@ -40,6 +40,9 @@ export async function connectCollector({ ...@@ -40,6 +40,9 @@ export async function connectCollector({
return true return true
}) })
spans.push(...filteredSpans) spans.push(...filteredSpans)
// Exporters can leave pooled sockets idle between tests. Close each
// response so a server keep-alive timeout cannot drop a later export.
res.setHeader('Connection', 'close')
res.statusCode = 202 res.statusCode = 202
res.end() res.end()
}) })
......
...@@ -137,6 +137,16 @@ describe.each( ...@@ -137,6 +137,16 @@ describe.each(
await expectAppRouteTrace('/api/app/param/data') await expectAppRouteTrace('/api/app/param/data')
}) })
it('closes collector connections after each export', async () => {
const response = await fetch(`http://localhost:${COLLECTOR_PORT}`, {
method: 'POST',
body: '[]',
})
expect(response.status).toBe(202)
expect(response.headers.get('connection')).toBe('close')
})
// Edge runtime is currently not implemented in custom-entrypoint-server.ts // Edge runtime is currently not implemented in custom-entrypoint-server.ts
const itEdge = useDirectEntrypointHandler ? it.skip : it const itEdge = useDirectEntrypointHandler ? it.skip : it
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment