Skip to content

Commit 725f380

Browse files
committed
fix(auth): clear MX-lookup timeout to avoid dangling timer on success
1 parent b2c931d commit 725f380

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

apps/sim/lib/messaging/email/validation.server.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,16 @@ export async function validateSignupEmailMx(email: string): Promise<SignupEmailC
4949
if (!domain) return { allowed: true }
5050

5151
let records: MxRecord[]
52+
let timeoutHandle: ReturnType<typeof setTimeout> | undefined
5253
try {
5354
records = await Promise.race([
5455
dns.resolveMx(domain),
55-
new Promise<never>((_, reject) =>
56-
setTimeout(() => reject(new Error('mx_lookup_timeout')), MX_LOOKUP_TIMEOUT_MS)
57-
),
56+
new Promise<never>((_, reject) => {
57+
timeoutHandle = setTimeout(
58+
() => reject(new Error('mx_lookup_timeout')),
59+
MX_LOOKUP_TIMEOUT_MS
60+
)
61+
}),
5862
])
5963
} catch (error) {
6064
const code = (error as NodeJS.ErrnoException).code
@@ -67,6 +71,8 @@ export async function validateSignupEmailMx(email: string): Promise<SignupEmailC
6771
error: getErrorMessage(error),
6872
})
6973
return { allowed: true }
74+
} finally {
75+
if (timeoutHandle) clearTimeout(timeoutHandle)
7076
}
7177

7278
if (!records || records.length === 0) {

0 commit comments

Comments
 (0)