@@ -268,6 +268,10 @@ export class Server {
268
268
} ;
269
269
}
270
270
271
+ const deferredCallback = ( error : Error | null , port : number ) => {
272
+ process . nextTick ( ( ) => callback ( error , port ) ) ;
273
+ }
274
+
271
275
const setupServer = ( ) : http2 . Http2Server | http2 . Http2SecureServer => {
272
276
let http2Server : http2 . Http2Server | http2 . Http2SecureServer ;
273
277
if ( creds . _isSecure ( ) ) {
@@ -386,7 +390,7 @@ export class Server {
386
390
// We only want one resolution result. Discard all future results
387
391
resolverListener . onSuccessfulResolution = ( ) => { } ;
388
392
if ( addressList . length === 0 ) {
389
- callback ( new Error ( `No addresses resolved for port ${ port } ` ) , 0 ) ;
393
+ deferredCallback ( new Error ( `No addresses resolved for port ${ port } ` ) , 0 ) ;
390
394
return ;
391
395
}
392
396
let bindResultPromise : Promise < BindResult > ;
@@ -409,26 +413,26 @@ export class Server {
409
413
if ( bindResult . count === 0 ) {
410
414
const errorString = `No address added out of total ${ addressList . length } resolved` ;
411
415
logging . log ( LogVerbosity . ERROR , errorString ) ;
412
- callback ( new Error ( errorString ) , 0 ) ;
416
+ deferredCallback ( new Error ( errorString ) , 0 ) ;
413
417
} else {
414
418
if ( bindResult . count < addressList . length ) {
415
419
logging . log (
416
420
LogVerbosity . INFO ,
417
421
`WARNING Only ${ bindResult . count } addresses added out of total ${ addressList . length } resolved`
418
422
) ;
419
423
}
420
- callback ( null , bindResult . port ) ;
424
+ deferredCallback ( null , bindResult . port ) ;
421
425
}
422
426
} ,
423
427
( error ) => {
424
428
const errorString = `No address added out of total ${ addressList . length } resolved` ;
425
429
logging . log ( LogVerbosity . ERROR , errorString ) ;
426
- callback ( new Error ( errorString ) , 0 ) ;
430
+ deferredCallback ( new Error ( errorString ) , 0 ) ;
427
431
}
428
432
) ;
429
433
} ,
430
434
onError : ( error ) => {
431
- callback ( new Error ( error . details ) , 0 ) ;
435
+ deferredCallback ( new Error ( error . details ) , 0 ) ;
432
436
} ,
433
437
} ;
434
438
0 commit comments