Skip to content

Commit 31ead71

Browse files
fix(trace): aggregate a trace's events outside aggregate to avoid a Node.js 24 V8 bug (#838)
When Maglev's code for `aggregate` bails out after V8 switched into it partway through the loop over the trace's events, Node.js 24's V8 rebuilds the object `aggregate` returns with its floating-point field shared across calls. A later trace's duration then overwrites an earlier one's, so a diff's base side reported the current side's duration. The loop now runs in its own method, so V8 never switches into `aggregate` mid-loop. See nodejs/node#66457
1 parent 54f4fe1 commit 31ead71

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

‎src/modalities/trace/aggregate.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,7 @@ class EventsAggregator {
334334
}
335335

336336
public aggregate(): AggregatedTrace {
337-
let position = 0
338-
for (const parsed of this.#trace.events) {
339-
this.#aggregateParsed(parsed, position++)
340-
}
337+
this.#aggregateEvents()
341338
this.#closeSpansOutside(undefined)
342339

343340
const spans = [
@@ -367,6 +364,18 @@ class EventsAggregator {
367364
}
368365
}
369366

367+
// Kept out of `aggregate`, so V8 never switches into Maglev's code for
368+
// `aggregate` partway through this loop. Node.js 24's V8 rebuilds the object
369+
// `aggregate` returns when that code bails out, sharing its floating-point
370+
// field across calls, so a later trace's duration overwrites an earlier one's:
371+
// https://github.com/nodejs/node/issues/66457
372+
#aggregateEvents(): void {
373+
let position = 0
374+
for (const parsed of this.#trace.events) {
375+
this.#aggregateParsed(parsed, position++)
376+
}
377+
}
378+
370379
#measureStartsFromTraceStart(spans: AggregatedTraceSpan[]): void {
371380
for (const span of spans) {
372381
for (const instance of span.instances) {

0 commit comments

Comments
 (0)