Skip to content

Commit c478e72

Browse files
committed
fix(webapp): cap default alerts seed with a 5s timeout
1 parent 27cb1f0 commit c478e72

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

apps/webapp/app/models/organization.server.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,25 @@ export async function createOrganization(
135135
return { ...organization };
136136
}
137137

138+
// The platform client has no request timeout; don't let a slow billing backend stall org creation.
139+
const SEED_ALERTS_TIMEOUT_MS = 5_000;
140+
138141
/** Seed default billing alerts for a new org. Never fails org creation. */
139142
async function seedDefaultBillingAlerts(organizationId: string): Promise<void> {
140143
if (!isBillingConfigured()) {
141144
return;
142145
}
143146

144-
const [error] = await tryCatch(setBillingAlert(organizationId, buildDefaultBillingAlerts()));
147+
let timer: NodeJS.Timeout | undefined;
148+
const timeout = new Promise<never>((_, reject) => {
149+
timer = setTimeout(() => reject(new Error("Timed out")), SEED_ALERTS_TIMEOUT_MS);
150+
});
151+
152+
const [error] = await tryCatch(
153+
Promise.race([setBillingAlert(organizationId, buildDefaultBillingAlerts()), timeout]).finally(
154+
() => clearTimeout(timer)
155+
)
156+
);
145157
if (error) {
146158
logger.warn("Failed to seed default billing alerts for new org", {
147159
organizationId,

0 commit comments

Comments
 (0)