Skip to content

Commit 5c0f300

Browse files
authored
Merge pull request Automattic#15089 from Automattic/vkarpov15/Automatticgh-15042
fix(connection): remove heartbeat check in load balanced mode
2 parents 15ce176 + d168bce commit 5c0f300

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/connection.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ Object.defineProperty(Connection.prototype, 'readyState', {
111111
if (
112112
this._readyState === STATES.connected &&
113113
this._lastHeartbeatAt != null &&
114+
// LoadBalanced topology (behind haproxy, including Atlas serverless instances) don't use heartbeats,
115+
// so we can't use this check in that case.
116+
this.client?.topology?.s?.description?.type !== 'LoadBalanced' &&
114117
typeof this.client?.topology?.s?.description?.heartbeatFrequencyMS === 'number' &&
115118
Date.now() - this._lastHeartbeatAt >= this.client.topology.s.description.heartbeatFrequencyMS * 2) {
116119
return STATES.disconnected;

lib/drivers/node-mongodb-native/connection.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,6 @@ function _setClient(conn, client, options, dbName) {
426426
}
427427

428428
conn.onOpen();
429-
if (client.topology?.s?.state === 'connected') {
430-
conn._lastHeartbeatAt = Date.now();
431-
}
432429

433430
for (const i in conn.collections) {
434431
if (utils.object.hasOwnProperty(conn.collections, i)) {

0 commit comments

Comments
 (0)