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-6469): pool is cleared before connection checkin on error #4296

Merged
merged 2 commits into from
Nov 19, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/cmap/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ export async function performInitialHandshake(
}

const start = new Date().getTime();
const response = await conn.command(ns('admin.$cmd'), handshakeDoc, handshakeOptions);

const response = await executeHandshake(handshakeDoc, handshakeOptions);

if (!('isWritablePrimary' in response)) {
// Provide hello-style response document.
Expand Down Expand Up @@ -175,6 +176,22 @@ export async function performInitialHandshake(
// Connection establishment is socket creation (tcp handshake, tls handshake, MongoDB handshake (saslStart, saslContinue))
// Once connection is established, command logging can log events (if enabled)
conn.established = true;

async function executeHandshake(handshakeDoc: Document, handshakeOptions: CommandOptions) {
try {
const handshakeResponse = await conn.command(
ns('admin.$cmd'),
handshakeDoc,
handshakeOptions
);
return handshakeResponse;
} catch (error) {
if (error instanceof MongoError) {
error.addErrorLabel(MongoErrorLabel.HandshakeError);
}
throw error;
}
}
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/cmap/connection_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
},
error => {
this[kPending]--;
this[kServer].handleError(error);
this.emitAndLog(
ConnectionPool.CONNECTION_CLOSED,
new ConnectionClosedEvent(
Expand Down Expand Up @@ -719,9 +720,6 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
// connection permits because that potentially delays the availability of
// the connection to a checkout request
this.createConnection((err, connection) => {
if (err) {
this[kServer].handleError(err);
}
if (!err && connection) {
this[kConnections].push(connection);
process.nextTick(() => this.processWaitQueue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ describe('Connection Monitoring and Pooling Spec Tests (Integration) - logging',
) {
return 'not applicable: waitQueueSize not supported';
}
if (test.description === 'Connection checkout fails due to error establishing connection') {
return 'TODO(NODE-5230): unskip this once event ordering issue is resolved';
}
return false;
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { loadSpecTests } from '../../spec';
import { type CmapTest, runCmapTestSuite } from '../../tools/cmap_spec_runner';
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';

describe('Connection Monitoring and Pooling (Node Driver)', function () {
const cmapTests: CmapTest[] = loadSpecTests(
Expand All @@ -17,10 +16,4 @@ describe('Connection Monitoring and Pooling (Node Driver)', function () {
}
]
});

// TODO(NODE-5230): Remove this once the actual unified tests (test/spec/connection-monitoring-and-pooling/logging) are passing
const unifiedTests = loadSpecTests(
'../integration/connection-monitoring-and-pooling/unified-cmap-node-specs'
);
runUnifiedSuite(unifiedTests);
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@
"type": "ConnectionCreated",
"address": 42
},
{
"type": "ConnectionPoolCleared",
"address": 42
},
{
"type": "ConnectionClosed",
"address": 42,
"connectionId": 42,
"reason": "error"
},
{
"type": "ConnectionPoolCleared",
"address": 42
}
],
"ignore": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ events:
address: 42
- type: ConnectionCreated
address: 42
- type: ConnectionPoolCleared
address: 42
- type: ConnectionClosed
address: 42
connectionId: 42
reason: error
- type: ConnectionPoolCleared
address: 42
ignore:
- ConnectionPoolCreated
Loading