Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-4831): check map value is not undefined #3477

Merged
merged 2 commits into from Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cmap/connection.ts
Expand Up @@ -384,7 +384,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
} else {
// Get the first orphaned operation description.
const entry = this[kQueue].entries().next();
if (entry) {
if (entry.value != null) {
const [requestId, orphaned]: [number, OperationDescription] = entry.value;
// If the orphaned operation description exists then set it.
operationDescription = orphaned;
Expand Down
28 changes: 28 additions & 0 deletions test/unit/cmap/connection.test.ts
Expand Up @@ -287,6 +287,34 @@ describe('new Connection()', function () {
});
});

context('when no operation description is in the queue', function () {
const document = { ok: 1 };

beforeEach(function () {
// @ts-expect-error: driverSocket does not fully satisfy the stream type, but that's okay
connection = sinon.spy(new Connection(driverSocket, connectionOptionsDefaults));
connection.isMonitoringConnection = true;
const queueSymbol = getSymbolFrom(connection, 'queue');
queue = connection[queueSymbol];
});

it('does not error', function () {
const msg = generateOpMsgBuffer(document);
const msgHeader: MessageHeader = {
length: msg.readInt32LE(0),
requestId: 2,
responseTo: 1,
opCode: msg.readInt32LE(12)
};
const msgBody = msg.subarray(16);

const message = new BinMsg(msg, msgHeader, msgBody);
expect(() => {
connection.onMessage(message);
}).to.not.throw();
});
});

context('when more than one operation description is in the queue', function () {
let spyOne;
let spyTwo;
Expand Down