@@ -20,6 +20,28 @@ import { logger } from './logger'
2020let machineIdModule : typeof import ( 'node-machine-id' ) | null = null
2121let systeminformationModule : typeof import ( 'systeminformation' ) | null = null
2222
23+ const ENHANCED_FINGERPRINT_TIMEOUT_MS = 3000
24+
25+ export function withTimeout < T > (
26+ promise : Promise < T > ,
27+ timeoutMs : number ,
28+ timeoutMessage : string ,
29+ ) : Promise < T > {
30+ let timeout : ReturnType < typeof setTimeout > | null = null
31+
32+ const timeoutPromise = new Promise < never > ( ( _ , reject ) => {
33+ timeout = setTimeout ( ( ) => {
34+ reject ( new Error ( timeoutMessage ) )
35+ } , timeoutMs )
36+ } )
37+
38+ return Promise . race ( [ promise , timeoutPromise ] ) . finally ( ( ) => {
39+ if ( timeout ) {
40+ clearTimeout ( timeout )
41+ }
42+ } )
43+ }
44+
2345async function getMachineId ( ) : Promise < string > {
2446 if ( ! machineIdModule ) {
2547 machineIdModule = await import ( 'node-machine-id' )
@@ -162,7 +184,11 @@ export function getFingerprintId(): Promise<string> {
162184 */
163185export async function calculateFingerprint ( ) : Promise < string > {
164186 try {
165- const fingerprint = await calculateEnhancedFingerprint ( )
187+ const fingerprint = await withTimeout (
188+ calculateEnhancedFingerprint ( ) ,
189+ ENHANCED_FINGERPRINT_TIMEOUT_MS ,
190+ `Enhanced CLI fingerprinting timed out after ${ ENHANCED_FINGERPRINT_TIMEOUT_MS } ms` ,
191+ )
166192 logger . debug (
167193 {
168194 fingerprintType : 'enhanced_cli' ,
0 commit comments