Skip to content

Commit 8a43e90

Browse files
committed
Fix race condition with shared variables
1 parent d8bd2dd commit 8a43e90

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/remix/src/server/instrumentServer.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,17 +320,18 @@ function wrapRequestHandler<T extends ServerBuild | (() => ServerBuild | Promise
320320
instrumentTracing?: boolean;
321321
},
322322
): RequestHandler {
323-
let resolvedBuild: ServerBuild | { build: ServerBuild };
324-
let name: string;
325-
let source: TransactionSource;
326-
327323
return async function (this: unknown, request: RemixRequest, loadContext?: AppLoadContext): Promise<Response> {
328324
const upperCaseMethod = request.method.toUpperCase();
329325
// We don't want to wrap OPTIONS and HEAD requests
330326
if (upperCaseMethod === 'OPTIONS' || upperCaseMethod === 'HEAD') {
331327
return origRequestHandler.call(this, request, loadContext);
332328
}
333329

330+
// These variables are declared inside the async function to avoid race conditions
331+
// across concurrent requests. Each request gets its own instance.
332+
let resolvedBuild: ServerBuild | { build: ServerBuild };
333+
let name: string;
334+
let source: TransactionSource;
334335
let resolvedRoutes: AgnosticRouteObject[] | undefined;
335336

336337
if (options?.instrumentTracing) {

0 commit comments

Comments
 (0)