Skip to content

Commit 5587eba

Browse files
Merge branch 'main' into local-aws
2 parents 576e8c6 + b35cbcf commit 5587eba

107 files changed

Lines changed: 3679 additions & 776 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.evergreen/config.yml

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,8 @@ tasks:
14251425
- func: assume secrets manager role
14261426
- func: run ldap tests
14271427
- name: test-socks5
1428-
tags: []
1428+
tags:
1429+
- socks5
14291430
commands:
14301431
- command: expansions.update
14311432
type: setup
@@ -1451,7 +1452,8 @@ tasks:
14511452
- func: bootstrap mongo-orchestration
14521453
- func: run socks5 tests
14531454
- name: test-socks5-tls
1454-
tags: []
1455+
tags:
1456+
- socks5-tls
14551457
commands:
14561458
- command: expansions.update
14571459
type: setup
@@ -1502,6 +1504,7 @@ tasks:
15021504
- name: test-tls-support-latest
15031505
tags:
15041506
- tls-support
1507+
- tls-support-latest
15051508
commands:
15061509
- command: expansions.update
15071510
type: setup
@@ -1517,6 +1520,7 @@ tasks:
15171520
- name: test-tls-support-8.0
15181521
tags:
15191522
- tls-support
1523+
- tls-support-8.0
15201524
commands:
15211525
- command: expansions.update
15221526
type: setup
@@ -1532,6 +1536,7 @@ tasks:
15321536
- name: test-tls-support-7.0
15331537
tags:
15341538
- tls-support
1539+
- tls-support-7.0
15351540
commands:
15361541
- command: expansions.update
15371542
type: setup
@@ -1547,6 +1552,7 @@ tasks:
15471552
- name: test-tls-support-6.0
15481553
tags:
15491554
- tls-support
1555+
- tls-support-6.0
15501556
commands:
15511557
- command: expansions.update
15521558
type: setup
@@ -1562,6 +1568,7 @@ tasks:
15621568
- name: test-tls-support-5.0
15631569
tags:
15641570
- tls-support
1571+
- tls-support-5.0
15651572
commands:
15661573
- command: expansions.update
15671574
type: setup
@@ -1577,6 +1584,7 @@ tasks:
15771584
- name: test-tls-support-4.4
15781585
tags:
15791586
- tls-support
1587+
- tls-support-4.4
15801588
commands:
15811589
- command: expansions.update
15821590
type: setup
@@ -1592,6 +1600,7 @@ tasks:
15921600
- name: test-tls-support-4.2
15931601
tags:
15941602
- tls-support
1603+
- tls-support-4.2
15951604
commands:
15961605
- command: expansions.update
15971606
type: setup
@@ -3075,9 +3084,6 @@ buildvariants:
30753084
CLIENT_ENCRYPTION: 'false'
30763085
TEST_CSFLE: 'false'
30773086
tasks:
3078-
- test-latest-server
3079-
- test-latest-replica_set
3080-
- test-latest-sharded_cluster
30813087
- test-rapid-server
30823088
- test-rapid-replica_set
30833089
- test-rapid-sharded_cluster
@@ -3099,12 +3105,6 @@ buildvariants:
30993105
- test-4.2-server
31003106
- test-4.2-replica_set
31013107
- test-4.2-sharded_cluster
3102-
- test-latest-server-v1-api
3103-
- test-socks5
3104-
- test-socks5-tls
3105-
- test-snappy-compression
3106-
- test-zstd-compression
3107-
- test-tls-support-latest
31083108
- test-tls-support-8.0
31093109
- test-tls-support-7.0
31103110
- test-tls-support-6.0
@@ -3119,9 +3119,6 @@ buildvariants:
31193119
CLIENT_ENCRYPTION: 'false'
31203120
TEST_CSFLE: 'false'
31213121
tasks:
3122-
- test-latest-server
3123-
- test-latest-replica_set
3124-
- test-latest-sharded_cluster
31253122
- test-rapid-server
31263123
- test-rapid-replica_set
31273124
- test-rapid-sharded_cluster
@@ -3143,12 +3140,6 @@ buildvariants:
31433140
- test-4.2-server
31443141
- test-4.2-replica_set
31453142
- test-4.2-sharded_cluster
3146-
- test-latest-server-v1-api
3147-
- test-socks5
3148-
- test-socks5-tls
3149-
- test-snappy-compression
3150-
- test-zstd-compression
3151-
- test-tls-support-latest
31523143
- test-tls-support-8.0
31533144
- test-tls-support-7.0
31543145
- test-tls-support-6.0
@@ -3163,9 +3154,6 @@ buildvariants:
31633154
CLIENT_ENCRYPTION: 'false'
31643155
TEST_CSFLE: 'false'
31653156
tasks:
3166-
- test-latest-server
3167-
- test-latest-replica_set
3168-
- test-latest-sharded_cluster
31693157
- test-rapid-server
31703158
- test-rapid-replica_set
31713159
- test-rapid-sharded_cluster
@@ -3187,12 +3175,6 @@ buildvariants:
31873175
- test-4.2-server
31883176
- test-4.2-replica_set
31893177
- test-4.2-sharded_cluster
3190-
- test-latest-server-v1-api
3191-
- test-socks5
3192-
- test-socks5-tls
3193-
- test-snappy-compression
3194-
- test-zstd-compression
3195-
- test-tls-support-latest
31963178
- test-tls-support-8.0
31973179
- test-tls-support-7.0
31983180
- test-tls-support-6.0

.evergreen/generate_evergreen_tasks.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ const WINDOWS_SKIP_TAGS = new Set([
4545
'auth',
4646
'load_balancer',
4747
'socks5-csfle',
48-
'oidc'
48+
'oidc',
49+
50+
// TODO: NODE-7356: enable skipped tests on windows
51+
'latest',
52+
'socks5',
53+
'socks5-tls',
54+
'tls-support-latest'
4955
]);
5056

5157
const TASKS = [];
@@ -181,7 +187,7 @@ TASKS.push(
181187
},
182188
{
183189
name: 'test-socks5',
184-
tags: [],
190+
tags: ['socks5'],
185191
commands: [
186192
updateExpansions({
187193
VERSION: 'latest',
@@ -208,7 +214,7 @@ TASKS.push(
208214
},
209215
{
210216
name: 'test-socks5-tls',
211-
tags: [],
217+
tags: ['socks5-tls'],
212218
commands: [
213219
updateExpansions({
214220
SSL: 'ssl',
@@ -298,7 +304,7 @@ AWS_LAMBDA_HANDLER_TASKS.push({
298304
for (const VERSION of TLS_VERSIONS) {
299305
TASKS.push({
300306
name: `test-tls-support-${VERSION}`,
301-
tags: ['tls-support'],
307+
tags: ['tls-support', `tls-support-${VERSION}`],
302308
commands: [
303309
updateExpansions({
304310
VERSION,

src/change_stream.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { MongoClient } from './mongo_client';
1818
import { type InferIdType, TypedEventEmitter } from './mongo_types';
1919
import type { AggregateOptions } from './operations/aggregate';
2020
import type { OperationParent } from './operations/command';
21+
import { DeprioritizedServers } from './sdam/server_selection';
2122
import type { ServerSessionId } from './sessions';
2223
import { CSOTTimeoutContext, type TimeoutContext } from './timeout';
2324
import { type AnyOptions, getTopology, type MongoDBNamespace, squashError } from './utils';
@@ -1073,7 +1074,8 @@ export class ChangeStream<
10731074
try {
10741075
await topology.selectServer(this.cursor.readPreference, {
10751076
operationName: 'reconnect topology in change stream',
1076-
timeoutContext: this.timeoutContext
1077+
timeoutContext: this.timeoutContext,
1078+
deprioritizedServers: new DeprioritizedServers()
10771079
});
10781080
this.cursor = this._createChangeStreamCursor(this.cursor.resumeOptions);
10791081
} catch {

src/cmap/auth/gssapi.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as dns from 'dns';
2+
import * as os from 'os';
23

34
import { getKerberos, type Kerberos, type KerberosClient } from '../../deps';
45
import { MongoInvalidArgumentError, MongoMissingCredentialsError } from '../../error';
@@ -97,7 +98,7 @@ async function makeKerberosClient(authContext: AuthContext): Promise<KerberosCli
9798
}
9899

99100
const spnHost = mechanismProperties.SERVICE_HOST ?? host;
100-
let spn = `${serviceName}${process.platform === 'win32' ? '/' : '@'}${spnHost}`;
101+
let spn = `${serviceName}${os.platform() === 'win32' ? '/' : '@'}${spnHost}`;
101102
if ('SERVICE_REALM' in mechanismProperties) {
102103
spn = `${spn}@${mechanismProperties.SERVICE_REALM}`;
103104
}

src/cmap/connect.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ import {
3535
/** @public */
3636
export type Stream = Socket | TLSSocket;
3737

38+
function applyBackpressureLabels(error: MongoError) {
39+
error.addErrorLabel(MongoErrorLabel.SystemOverloadedError);
40+
error.addErrorLabel(MongoErrorLabel.RetryableError);
41+
}
42+
3843
export async function connect(options: ConnectionOptions): Promise<Connection> {
3944
let connection: Connection | null = null;
4045
try {
@@ -103,6 +108,8 @@ export async function performInitialHandshake(
103108
const authContext = new AuthContext(conn, credentials, options);
104109
conn.authContext = authContext;
105110

111+
// If we encounter an error preparing the handshake document, do NOT apply backpressure labels. Errors
112+
// encountered building the handshake document are all client-side, and do not indicate an overloaded server.
106113
const handshakeDoc = await prepareHandshakeDocument(authContext);
107114

108115
// @ts-expect-error: TODO(NODE-5141): The options need to be filtered properly, Connection options differ from Command options
@@ -163,12 +170,15 @@ export async function performInitialHandshake(
163170
try {
164171
await provider.auth(authContext);
165172
} catch (error) {
173+
// NOTE: If we encounter an error authenticating a connection, do NOT apply backpressure labels.
174+
166175
if (error instanceof MongoError) {
167176
error.addErrorLabel(MongoErrorLabel.HandshakeError);
168177
if (needsRetryableWriteLabel(error, response.maxWireVersion, conn.description.type)) {
169178
error.addErrorLabel(MongoErrorLabel.RetryableWriteError);
170179
}
171180
}
181+
172182
throw error;
173183
}
174184
}
@@ -189,6 +199,11 @@ export async function performInitialHandshake(
189199
if (error instanceof MongoError) {
190200
error.addErrorLabel(MongoErrorLabel.HandshakeError);
191201
}
202+
// If we encounter a network error executing the initial handshake, apply backpressure labels.
203+
if (error instanceof MongoNetworkError) {
204+
applyBackpressureLabels(error);
205+
}
206+
192207
throw error;
193208
}
194209
}
@@ -424,6 +439,10 @@ export async function makeSocket(options: MakeConnectionOptions): Promise<Stream
424439
socket = await connectedSocket;
425440
return socket;
426441
} catch (error) {
442+
// If we encounter an error while establishing a socket, apply the backpressure labels to it. We cannot
443+
// differentiate between DNS, TLS errors and network errors without refactoring our connection establishment to
444+
// handle all three steps separately.
445+
applyBackpressureLabels(error);
427446
socket.destroy();
428447
throw error;
429448
} finally {

src/cmap/connection_pool.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
231231
this.mongoLogger = this.server.topology.client?.mongoLogger;
232232
this.component = 'connection';
233233

234-
process.nextTick(() => {
234+
queueMicrotask(() => {
235235
this.emitAndLog(ConnectionPool.CONNECTION_POOL_CREATED, new ConnectionPoolCreatedEvent(this));
236236
});
237237
}
@@ -342,7 +342,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
342342
});
343343

344344
this.waitQueue.push(waitQueueMember);
345-
process.nextTick(() => this.processWaitQueue());
345+
queueMicrotask(() => this.processWaitQueue());
346346

347347
try {
348348
timeout?.throwIfExpired();
@@ -405,7 +405,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
405405
this.destroyConnection(connection, reason);
406406
}
407407

408-
process.nextTick(() => this.processWaitQueue());
408+
queueMicrotask(() => this.processWaitQueue());
409409
}
410410

411411
/**
@@ -461,7 +461,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
461461
}
462462

463463
if (interruptInUseConnections) {
464-
process.nextTick(() => this.interruptInUseConnections(oldGeneration));
464+
queueMicrotask(() => this.interruptInUseConnections(oldGeneration));
465465
}
466466

467467
this.processWaitQueue();
@@ -702,7 +702,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
702702
this.createConnection((err, connection) => {
703703
if (!err && connection) {
704704
this.connections.push(connection);
705-
process.nextTick(() => this.processWaitQueue());
705+
queueMicrotask(() => this.processWaitQueue());
706706
}
707707
if (this.poolState === PoolState.ready) {
708708
clearTimeout(this.minPoolSizeTimer);
@@ -809,7 +809,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
809809
waitQueueMember.resolve(connection);
810810
}
811811
}
812-
process.nextTick(() => this.processWaitQueue());
812+
queueMicrotask(() => this.processWaitQueue());
813813
});
814814
}
815815
this.processingWaitQueue = false;

src/cmap/handshake/client_metadata.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ export async function makeClientMetadata(
157157

158158
// Note: order matters, os.type is last so it will be removed last if we're at maxSize
159159
const osInfo = new Map()
160-
.set('name', process.platform)
161-
.set('architecture', process.arch)
160+
.set('name', os.platform())
161+
.set('architecture', os.arch())
162162
.set('version', os.release())
163163
.set('type', os.type());
164164

src/error.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ export const MongoErrorLabel = Object.freeze({
9999
ResetPool: 'ResetPool',
100100
PoolRequestedRetry: 'PoolRequestedRetry',
101101
InterruptInUseConnections: 'InterruptInUseConnections',
102-
NoWritesPerformed: 'NoWritesPerformed'
102+
NoWritesPerformed: 'NoWritesPerformed',
103+
RetryableError: 'RetryableError',
104+
SystemOverloadedError: 'SystemOverloadedError'
103105
} as const);
104106

105107
/** @public */

0 commit comments

Comments
 (0)