Skip to content

Commit 7d0fe48

Browse files
committed
fix race condition and registering fallback incorrectly
1 parent 6b0eb4f commit 7d0fe48

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

packages/browser/src/tracing/request.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -274,24 +274,24 @@ function addHTTPTimings(span: Span, client: Client): void {
274274

275275
span.end = (endTimestamp?: SpanTimeInput) => {
276276
capturedEndTimestamp = endTimestamp;
277-
};
278277

279-
const endSpanAndCleanup = (): void => {
280-
if (isEnded) {
281-
return;
282-
}
283-
isEnded = true;
284-
setTimeout(cleanup);
285-
originalEnd(capturedEndTimestamp);
286-
clearTimeout(fallbackTimeout);
278+
const endSpanAndCleanup = (): void => {
279+
if (isEnded) {
280+
return;
281+
}
282+
isEnded = true;
283+
setTimeout(cleanup);
284+
originalEnd(capturedEndTimestamp);
285+
clearTimeout(fallbackTimeout);
286+
};
287+
288+
onEntryFound = endSpanAndCleanup;
289+
290+
// Fallback: always end the span after HTTP_TIMING_WAIT_MS even if no
291+
// PerformanceResourceTiming entry arrives (e.g. cross-origin without
292+
// Timing-Allow-Origin, or the browser didn't fire the observer in time).
293+
const fallbackTimeout = setTimeout(endSpanAndCleanup, HTTP_TIMING_WAIT_MS);
287294
};
288-
289-
onEntryFound = endSpanAndCleanup;
290-
291-
// Fallback: always end the span after HTTP_TIMING_WAIT_MS even if no
292-
// PerformanceResourceTiming entry arrives (e.g. cross-origin without
293-
// Timing-Allow-Origin, or the browser didn't fire the observer in time).
294-
const fallbackTimeout = setTimeout(endSpanAndCleanup, HTTP_TIMING_WAIT_MS);
295295
}
296296

297297
const cleanup = addPerformanceInstrumentationHandler('resource', ({ entries }) => {

0 commit comments

Comments
 (0)