Skip to content

Commit 4a6ad4f

Browse files
fix bug
1 parent 0d2b083 commit 4a6ad4f

File tree

9 files changed

+1101
-11
lines changed

9 files changed

+1101
-11
lines changed

src/cmap/connect.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ export async function performInitialHandshake(
113113
}
114114

115115
const start = new Date().getTime();
116-
const response = await conn.command(ns('admin.$cmd'), handshakeDoc, handshakeOptions);
116+
117+
const response = await executeHandshake(handshakeDoc, handshakeOptions);
117118

118119
if (!('isWritablePrimary' in response)) {
119120
// Provide hello-style response document.
@@ -175,6 +176,22 @@ export async function performInitialHandshake(
175176
// Connection establishment is socket creation (tcp handshake, tls handshake, MongoDB handshake (saslStart, saslContinue))
176177
// Once connection is established, command logging can log events (if enabled)
177178
conn.established = true;
179+
180+
async function executeHandshake(handshakeDoc: Document, handshakeOptions: CommandOptions) {
181+
try {
182+
const handshakeResponse = await conn.command(
183+
ns('admin.$cmd'),
184+
handshakeDoc,
185+
handshakeOptions
186+
);
187+
return handshakeResponse;
188+
} catch (error) {
189+
if (error instanceof MongoError) {
190+
error.addErrorLabel(MongoErrorLabel.HandshakeError);
191+
}
192+
throw error;
193+
}
194+
}
178195
}
179196

180197
/**

src/cmap/connection_pool.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
681681
},
682682
error => {
683683
this[kPending]--;
684+
this[kServer].handleError(error);
684685
this.emitAndLog(
685686
ConnectionPool.CONNECTION_CLOSED,
686687
new ConnectionClosedEvent(
@@ -715,9 +716,6 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
715716
// connection permits because that potentially delays the availability of
716717
// the connection to a checkout request
717718
this.createConnection((err, connection) => {
718-
if (err) {
719-
this[kServer].handleError(err);
720-
}
721719
if (!err && connection) {
722720
this[kConnections].push(connection);
723721
process.nextTick(() => this.processWaitQueue());

test/spec/connection-monitoring-and-pooling/cmap-format/pool-create-min-size-error.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@
4949
"type": "ConnectionCreated",
5050
"address": 42
5151
},
52+
{
53+
"type": "ConnectionPoolCleared",
54+
"address": 42
55+
},
5256
{
5357
"type": "ConnectionClosed",
5458
"address": 42,
5559
"connectionId": 42,
5660
"reason": "error"
57-
},
58-
{
59-
"type": "ConnectionPoolCleared",
60-
"address": 42
6161
}
6262
],
6363
"ignore": [

test/spec/connection-monitoring-and-pooling/cmap-format/pool-create-min-size-error.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ events:
3030
address: 42
3131
- type: ConnectionCreated
3232
address: 42
33+
- type: ConnectionPoolCleared
34+
address: 42
3335
- type: ConnectionClosed
3436
address: 42
3537
connectionId: 42
3638
reason: error
37-
- type: ConnectionPoolCleared
38-
address: 42
3939
ignore:
4040
- ConnectionPoolCreated

0 commit comments

Comments
 (0)