Skip to content

Commit

Permalink
Revert "chore: move logic out of monitoring check"
Browse files Browse the repository at this point in the history
This reverts commit c670bda.
  • Loading branch information
durran committed Nov 15, 2022
1 parent 5887b1f commit a0306ce
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/cmap/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,24 +374,23 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
this.emit('message', message);
let operationDescription = this[kQueue].get(message.responseTo);

// Protect against multiplexing.
if (this[kQueue].size > 1) {
this.onError(new MongoRuntimeError(INVALID_QUEUE_SIZE));
return;
}

if (!operationDescription && this.isMonitoringConnection) {
// This is how we recover when the initial hello's requestId is not
// the responseTo when hello responses have been skipped:

// Get the first orphaned operation description.
const entry = this[kQueue].entries().next();
if (entry) {
const [requestId, orphaned]: [number, OperationDescription] = entry.value;
// If the orphaned operation description exists then set it.
operationDescription = orphaned;
// Remove the entry with the bad request id from the queue.
this[kQueue].delete(requestId);
// First check if the map is of invalid size
if (this[kQueue].size > 1) {
this.onError(new MongoRuntimeError(INVALID_QUEUE_SIZE));
} else {
// Get the first orphaned operation description.
const entry = this[kQueue].entries().next();
if (entry) {
const [requestId, orphaned]: [number, OperationDescription] = entry.value;
// If the orphaned operation description exists then set it.
operationDescription = orphaned;
// Remove the entry with the bad request id from the queue.
this[kQueue].delete(requestId);
}
}
}

Expand Down

0 comments on commit a0306ce

Please sign in to comment.