@@ -300,14 +300,18 @@ export class RFC8252HTTPServer {
300
300
*/
301
301
public get listeningPort ( ) : number | undefined {
302
302
if ( this . servers . length === 0 ) return undefined ;
303
- const ports = new Set (
304
- this . servers . map ( ( srv ) => ( srv . address ( ) as AddressInfo ) ?. port )
303
+ const addresses : AddressInfo [ ] = this . servers . map (
304
+ ( srv ) => srv . address ( ) as AddressInfo
305
305
) ;
306
+ const ports = new Set ( addresses . map ( ( addr ) => addr . port ) ) ;
306
307
const port = ports . size === 1 && [ ...ports ] [ 0 ] ;
307
308
if ( typeof port !== 'number' ) {
309
+ const addressesDebugInfo = addresses
310
+ . map ( ( addr ) => JSON . stringify ( addr ) )
311
+ . join ( ',' ) ;
308
312
// Should never happen
309
313
throw new MongoDBOIDCError (
310
- `Server is listening in inconsistent state: ${ [ ... ports ] . join ( ',' ) } `
314
+ `Server is listening in inconsistent state: ${ addressesDebugInfo } `
311
315
) ;
312
316
}
313
317
return port ;
@@ -343,8 +347,11 @@ export class RFC8252HTTPServer {
343
347
) ;
344
348
}
345
349
350
+ const urlPort = this . redirectUrl . port === '' ? 80 : + this . redirectUrl . port ;
351
+
346
352
this . logger . emit ( 'mongodb-oidc-plugin:local-listen-started' , {
347
353
url : this . redirectUrl . toString ( ) ,
354
+ urlPort,
348
355
} ) ;
349
356
350
357
// https://www.rfc-editor.org/rfc/rfc8252#section-7.3 states:
@@ -363,9 +370,18 @@ export class RFC8252HTTPServer {
363
370
let hostname = this . redirectUrl . hostname ;
364
371
if ( hostname . startsWith ( '[' ) && hostname . endsWith ( ']' ) )
365
372
hostname = hostname . slice ( 1 , - 1 ) ;
366
- const dnsResults = await dns . lookup ( hostname , {
367
- all : true ,
368
- hints : ADDRCONFIG ,
373
+ const dnsResults = (
374
+ await dns . lookup ( hostname , {
375
+ all : true ,
376
+ hints : ADDRCONFIG ,
377
+ } )
378
+ ) . map ( ( { address, family } ) => ( { address, family } ) ) ;
379
+
380
+ this . logger . emit ( 'mongodb-oidc-plugin:local-listen-resolved-hostname' , {
381
+ url : this . redirectUrl . toString ( ) ,
382
+ urlPort,
383
+ hostname,
384
+ interfaces : dnsResults ,
369
385
} ) ;
370
386
371
387
if ( dnsResults . length === 0 ) {
@@ -375,9 +391,6 @@ export class RFC8252HTTPServer {
375
391
}
376
392
377
393
try {
378
- const urlPort =
379
- this . redirectUrl . port === '' ? 80 : + this . redirectUrl . port ;
380
-
381
394
// Two scenarios: Either we are listening on an arbitrary port here,
382
395
// or listening on a specific port. Using an arbitrary port has the
383
396
// advantage that the OS will allocate a free one for us, while a
@@ -406,7 +419,7 @@ export class RFC8252HTTPServer {
406
419
if ( typeof port !== 'number' ) {
407
420
// Should never happen
408
421
throw new MongoDBOIDCError (
409
- `Listening on ${ dnsResults [ 0 ] . address } did not return a port`
422
+ `Listening on ${ dnsResults [ 0 ] . address } (family = ${ dnsResults [ 0 ] . family } ) did not return a port`
410
423
) ;
411
424
}
412
425
}
@@ -429,13 +442,16 @@ export class RFC8252HTTPServer {
429
442
await this . close ( ) ;
430
443
this . logger . emit ( 'mongodb-oidc-plugin:local-listen-failed' , {
431
444
url : this . redirectUrl . toString ( ) ,
445
+ error : String (
446
+ err && typeof err === 'object' && 'message' in err ? err . message : err
447
+ ) ,
432
448
} ) ;
433
449
throw err ;
434
450
}
435
451
436
452
this . logger . emit ( 'mongodb-oidc-plugin:local-listen-succeeded' , {
437
453
url : this . listeningRedirectUrl || '' ,
438
- interfaces : dnsResults . map ( ( dnsResult ) => dnsResult . address ) ,
454
+ interfaces : dnsResults ,
439
455
} ) ;
440
456
}
441
457
0 commit comments