File tree Expand file tree Collapse file tree
apps/sim/lib/messaging/email Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments