@@ -374,24 +374,23 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
374
374
this . emit ( 'message' , message ) ;
375
375
let operationDescription = this [ kQueue ] . get ( message . responseTo ) ;
376
376
377
- // Protect against multiplexing.
378
- if ( this [ kQueue ] . size > 1 ) {
379
- this . onError ( new MongoRuntimeError ( INVALID_QUEUE_SIZE ) ) ;
380
- return ;
381
- }
382
-
383
377
if ( ! operationDescription && this . isMonitoringConnection ) {
384
378
// This is how we recover when the initial hello's requestId is not
385
379
// the responseTo when hello responses have been skipped:
386
380
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
+ }
395
394
}
396
395
}
397
396
0 commit comments