Skip to content

Commit 00c3e82

Browse files
Merge branch 'main' into NODE-4691-kill-in-fight-ops-on-heartbeat-timeout
2 parents a573e0e + 9795cdb commit 00c3e82

File tree

7 files changed

+57
-15
lines changed

7 files changed

+57
-15
lines changed

etc/check-remote.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#! /bin/bash
2+
3+
if git remote get-url --push origin | grep -qv "github.com:mongodb"; then
4+
echo "git remote does not match node-mongodb-native. are you working off of a fork?"
5+
exit 1
6+
fi

etc/docs/build.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ async function updateSiteTemplateForNewVersion(
7373
}
7474

7575
async function main() {
76+
await exec('bash ./etc/check-remote.sh');
77+
7678
chdir(__dirname);
7779

7880
const { tag, status, skipPrompts } = getCommandLineArguments();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"fix:eslint": "npm run check:eslint -- --fix",
122122
"prepare": "node etc/prepare.js",
123123
"preview:docs": "ts-node etc/docs/preview.ts",
124-
"release": "standard-version -a -i HISTORY.md",
124+
"release": "bash etc/check-remote.sh && standard-version -a -i HISTORY.md",
125125
"test": "npm run check:lint && npm run test:all",
126126
"test:all": "npm run check:unit && npm run check:test",
127127
"update:docs": "npm run build:docs -- --yes"

src/cmap/auth/mongodb_aws.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as url from 'url';
44

55
import type { Binary, BSONSerializeOptions } from '../../bson';
66
import * as BSON from '../../bson';
7-
import { aws4, credentialProvider } from '../../deps';
7+
import { aws4, getAwsCredentialProvider } from '../../deps';
88
import {
99
MongoAWSError,
1010
MongoCompatibilityError,
@@ -198,6 +198,8 @@ function makeTempCredentials(credentials: MongoCredentials, callback: Callback<M
198198
);
199199
}
200200

201+
const credentialProvider = getAwsCredentialProvider();
202+
201203
// Check if the AWS credential provider from the SDK is present. If not,
202204
// use the old method.
203205
if ('kModuleError' in credentialProvider) {

src/cmap/connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
384384
} else {
385385
// Get the first orphaned operation description.
386386
const entry = this[kQueue].entries().next();
387-
if (entry) {
387+
if (entry.value != null) {
388388
const [requestId, orphaned]: [number, OperationDescription] = entry.value;
389389
// If the orphaned operation description exists then set it.
390390
operationDescription = orphaned;

src/deps.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,22 @@ type CredentialProvider = {
7272
fromNodeProviderChain(this: void): () => Promise<AWSCredentials>;
7373
};
7474

75-
export let credentialProvider: CredentialProvider | { kModuleError: MongoMissingDependencyError } =
76-
makeErrorModule(
77-
new MongoMissingDependencyError(
78-
'Optional module `@aws-sdk/credential-providers` not found.' +
79-
' Please install it to enable getting aws credentials via the official sdk.'
80-
)
81-
);
82-
83-
try {
84-
// Ensure you always wrap an optional require in the try block NODE-3199
85-
credentialProvider = require('@aws-sdk/credential-providers');
86-
} catch {} // eslint-disable-line
75+
export function getAwsCredentialProvider():
76+
| CredentialProvider
77+
| { kModuleError: MongoMissingDependencyError } {
78+
try {
79+
// Ensure you always wrap an optional require in the try block NODE-3199
80+
const credentialProvider = require('@aws-sdk/credential-providers');
81+
return credentialProvider;
82+
} catch {
83+
return makeErrorModule(
84+
new MongoMissingDependencyError(
85+
'Optional module `@aws-sdk/credential-providers` not found.' +
86+
' Please install it to enable getting aws credentials via the official sdk.'
87+
)
88+
);
89+
}
90+
}
8791

8892
type SnappyLib = {
8993
[PKG_VERSION]: { major: number; minor: number; patch: number };

test/unit/cmap/connection.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,34 @@ describe('new Connection()', function () {
287287
});
288288
});
289289

290+
context('when no operation description is in the queue', function () {
291+
const document = { ok: 1 };
292+
293+
beforeEach(function () {
294+
// @ts-expect-error: driverSocket does not fully satisfy the stream type, but that's okay
295+
connection = sinon.spy(new Connection(driverSocket, connectionOptionsDefaults));
296+
connection.isMonitoringConnection = true;
297+
const queueSymbol = getSymbolFrom(connection, 'queue');
298+
queue = connection[queueSymbol];
299+
});
300+
301+
it('does not error', function () {
302+
const msg = generateOpMsgBuffer(document);
303+
const msgHeader: MessageHeader = {
304+
length: msg.readInt32LE(0),
305+
requestId: 2,
306+
responseTo: 1,
307+
opCode: msg.readInt32LE(12)
308+
};
309+
const msgBody = msg.subarray(16);
310+
311+
const message = new BinMsg(msg, msgHeader, msgBody);
312+
expect(() => {
313+
connection.onMessage(message);
314+
}).to.not.throw();
315+
});
316+
});
317+
290318
context('when more than one operation description is in the queue', function () {
291319
let spyOne;
292320
let spyTwo;

0 commit comments

Comments
 (0)