Skip to content

Commit

Permalink
Merge pull request #15089 from Automattic/vkarpov15/gh-15042
Browse files Browse the repository at this point in the history
fix(connection): remove heartbeat check in load balanced mode
  • Loading branch information
vkarpov15 authored Dec 12, 2024
2 parents 15ce176 + d168bce commit 5c0f300
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ Object.defineProperty(Connection.prototype, 'readyState', {
if (
this._readyState === STATES.connected &&
this._lastHeartbeatAt != null &&
// LoadBalanced topology (behind haproxy, including Atlas serverless instances) don't use heartbeats,
// so we can't use this check in that case.
this.client?.topology?.s?.description?.type !== 'LoadBalanced' &&
typeof this.client?.topology?.s?.description?.heartbeatFrequencyMS === 'number' &&
Date.now() - this._lastHeartbeatAt >= this.client.topology.s.description.heartbeatFrequencyMS * 2) {
return STATES.disconnected;
Expand Down
3 changes: 0 additions & 3 deletions lib/drivers/node-mongodb-native/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,6 @@ function _setClient(conn, client, options, dbName) {
}

conn.onOpen();
if (client.topology?.s?.state === 'connected') {
conn._lastHeartbeatAt = Date.now();
}

for (const i in conn.collections) {
if (utils.object.hasOwnProperty(conn.collections, i)) {
Expand Down

0 comments on commit 5c0f300

Please sign in to comment.