Skip to content

fix(MongoDB): Add timeout support and harden replica set connections#5204

Merged
matejk merged 3 commits intomainfrom
mongodb-replica-set-use-timeouts-and-fixes
Mar 10, 2026
Merged

fix(MongoDB): Add timeout support and harden replica set connections#5204
matejk merged 3 commits intomainfrom
mongodb-replica-set-use-timeouts-and-fixes

Conversation

@matejk
Copy link
Copy Markdown
Contributor

@matejk matejk commented Feb 13, 2026

Summary

  • Add connect/socket timeout support to all MongoDB connection paths (ReplicaSet, ReplicaSetConnection, PoolableConnectionFactory) to prevent indefinite hangs when servers are unreachable
  • Fix retry path in executeWithRetry() dropping per-connection timeouts
  • Fix timeout-aware createConnection() bypassing custom SocketFactory (e.g., SSL/TLS)
  • Implement MongoDB spec-compliant maxStalenessSeconds using lastWrite.lastWriteDate from hello response
  • Add waitForServerAvailability() timeout-aware overload
  • Snapshot config fields under lock to eliminate data races
  • Replace busy-wait monitor sleep loop with condition_variable
  • Harden BSON parsing with size validation (document, string, binary, cstring)
  • Fix assertion checking wrong variable in MessageHeader::setMessageLength()
  • Fix duplicate "name" field in Database::createIndex()
  • Fix ObjectId::timestamp() portability (shift-and-OR instead of reinterpret_cast)
  • Fix OpMsgCursor::isActive() to use _cursorID != 0 instead of > 0
  • Centralize BSON/protocol constants in MongoDB.h

Test plan

  • All 89 MongoDB tests pass (MongoDB-testrunner -all)
  • 5 new timeout tests verify connections don't hang with unreachable servers
  • Integration test with live replica set (manual)

@matejk matejk added this to the Release 1.15.1 milestone Feb 13, 2026
@matejk matejk requested a review from aleks-f February 13, 2026 12:31
@matejk matejk force-pushed the mongodb-replica-set-use-timeouts-and-fixes branch from c2f4e7b to c32dc52 Compare February 14, 2026 16:22
@matejk matejk force-pushed the mongodb-replica-set-use-timeouts-and-fixes branch from c32dc52 to 9231f2c Compare February 23, 2026 14:43
@matejk matejk force-pushed the mongodb-replica-set-use-timeouts-and-fixes branch from 9231f2c to 06f8afd Compare March 8, 2026 09:41
@matejk matejk merged commit 14f7a2d into main Mar 10, 2026
102 checks passed
@matejk matejk deleted the mongodb-replica-set-use-timeouts-and-fixes branch March 10, 2026 18:21
@matejk matejk self-assigned this Mar 10, 2026
matejk added a commit that referenced this pull request Mar 10, 2026
…5204)

* fix(MongoDB): Add timeouts to network connections to database to prevent hangs when servers are not accessible.

* enh(MongoDB): Many document consistency checks and improvements.

* enh(MongoDB): Improved handling of monodb replica sets by using last write reported from hello.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant