@@ -374,23 +374,24 @@ 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
+
377
383
if ( ! operationDescription && this . isMonitoringConnection ) {
378
384
// This is how we recover when the initial hello's requestId is not
379
385
// the responseTo when hello responses have been skipped:
380
386
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 ) ;
394
395
}
395
396
}
396
397
0 commit comments