Skip to content

Commit e98c0c0

Browse files
committed
fix(webapp): guard the workload-auth-gate metric with singleton() to stop the dev-server HMR 'already registered' crash
1 parent 96e69ad commit e98c0c0

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

apps/webapp/app/v3/services/worker/workerGroupTokenService.server.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,20 @@ if (workloadCreatedAtGateEnabled && !workloadTokenCutoff) {
6262

6363
type WorkloadGateAction = "start" | "complete" | "continue" | "snapshots_since";
6464

65-
const workloadAuthGateCounter = new Counter({
66-
name: "workload_auth_gate_total",
67-
help: "Deployment token authorization outcomes on worker actions",
68-
labelNames: ["outcome", "action"] as const,
69-
registers: [metricsRegister],
70-
});
65+
// Wrapped in singleton() so a dev HMR re-eval of this module reuses the existing counter instead
66+
// of calling `new Counter` again — prom-client throws "already registered" on the second
67+
// registration, which crashes the dev server. Matches authenticatedWorkerInstanceCache above; a
68+
// no-op in prod (the module evaluates once).
69+
const workloadAuthGateCounter = singleton(
70+
"workloadAuthGateCounter",
71+
() =>
72+
new Counter({
73+
name: "workload_auth_gate_total",
74+
help: "Deployment token authorization outcomes on worker actions",
75+
labelNames: ["outcome", "action"] as const,
76+
registers: [metricsRegister],
77+
})
78+
);
7179

7280
function createAuthenticatedWorkerInstanceCache() {
7381
return createCache({

0 commit comments

Comments
 (0)