@@ -374,24 +374,23 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
374374 this . emit ( 'message' , message ) ;
375375 let operationDescription = this [ kQueue ] . get ( message . responseTo ) ;
376376
377- // Protect against multiplexing.
378- if ( this [ kQueue ] . size > 1 ) {
379- this . onError ( new MongoRuntimeError ( INVALID_QUEUE_SIZE ) ) ;
380- return ;
381- }
382-
383377 if ( ! operationDescription && this . isMonitoringConnection ) {
384378 // This is how we recover when the initial hello's requestId is not
385379 // the responseTo when hello responses have been skipped:
386380
387- // Get the first orphaned operation description.
388- const entry = this [ kQueue ] . entries ( ) . next ( ) ;
389- if ( entry ) {
390- const [ requestId , orphaned ] : [ number , OperationDescription ] = entry . value ;
391- // If the orphaned operation description exists then set it.
392- operationDescription = orphaned ;
393- // Remove the entry with the bad request id from the queue.
394- this [ kQueue ] . delete ( requestId ) ;
381+ // First check if the map is of invalid size
382+ if ( this [ kQueue ] . size > 1 ) {
383+ this . onError ( new MongoRuntimeError ( INVALID_QUEUE_SIZE ) ) ;
384+ } else {
385+ // Get the first orphaned operation description.
386+ const entry = this [ kQueue ] . entries ( ) . next ( ) ;
387+ if ( entry ) {
388+ const [ requestId , orphaned ] : [ number , OperationDescription ] = entry . value ;
389+ // If the orphaned operation description exists then set it.
390+ operationDescription = orphaned ;
391+ // Remove the entry with the bad request id from the queue.
392+ this [ kQueue ] . delete ( requestId ) ;
393+ }
395394 }
396395 }
397396
0 commit comments