Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion web/services/vms/routeHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Span } from "@opentelemetry/api";
import { trace } from "@opentelemetry/api";
import { after } from "next/server";
import {
activeTraceIds,
Expand Down Expand Up @@ -1069,9 +1070,16 @@ function normalizedOptionalString(value: string | null | undefined): string | nu
*/
export function runAfterResponse(work: () => Promise<void>): void {
const guarded = () => work().catch((err) => console.error("[VM] deferred work failed", err));
let mode: "after" | "detached" = "after";
try {
after(guarded);
} catch {
} catch (err) {
// Next throws E91 when the platform gave it no `waitUntil`. Detached work
// then dies the moment the function is frozen, so say so where it can be
// seen: a log line before the response and an attribute on the request span.
mode = "detached";
console.warn(`[VM] after() unavailable, running deferred work detached: ${err instanceof Error ? err.message : String(err)}`);
void guarded();
}
trace.getActiveSpan()?.setAttribute("cmux.after_response.mode", mode);
}