@@ -374,23 +374,24 @@ 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+
377383 if ( ! operationDescription && this . isMonitoringConnection ) {
378384 // This is how we recover when the initial hello's requestId is not
379385 // the responseTo when hello responses have been skipped:
380386
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- }
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 ) ;
394395 }
395396 }
396397
0 commit comments