[DRIVERS-961] Support serverSelectionTryOnce in multi-threaded drivers Created: 25/Oct/19  Updated: 29/Jul/20

Status: Blocked
Project: Drivers
Component/s: SDAM
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Tomer Yakir Assignee: Rachelle Palmer
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related

 Description   

The current spec indicates that single-threaded drivers must implement serverselectiontryonce but multi-threaded drivers must not.

There's benefit in implementing serverselectiontryonce in multi-threaded drivers as well so they can fail fast in case the server isn't running.
Using a low serverSelectionTimeout isn't sufficient as we need to distinguish between a case in which the server is actually down (where the dialer returns connection refused) or the connection is closed and other cases in which the server is simply slow to respond.

Current workarounds are a bit cumbersome - for example when working with the Go Driver we were able to workaround this using the following approaches:
1. Connect to the host:port with a simple TCP dialer before we attempt to Connect/Ping using the driver
2. Pass on a custom dialer with a cancel function and invoke the cancel function if we hit "connection refused"

To highlight the benefit of this (on top of cleaner code) - this is expected to introduce a significant performance boost to the MongoDB agent, especially in large clusters deployments



 Comments   
Comment by Esha Bhargava [ 09/Mar/20 ]

rachelle.palmer can you have a look at this one?

Comment by Oleg Pudeyev (Inactive) [ 22/Jan/20 ]

This came up before: https://jira.mongodb.org/browse/SPEC-1167

We currently recommend lowering server selection timeout from its default in both development and production environments (for different reasons): https://docs.mongodb.com/ruby-driver/master/tutorials/ruby-driver-create-client/#development-configuration

FWIW, Ruby driver implements something similar to serverselectiontryonce for legacy compatibility, to provide the illusion of the driver synchronously scanning each server before returning from constructor (but the scanning time is bound by server selection timeout, and servers are scanned in parallel; the scan also doesn't stop on a primary or a particular server type but tries to contact each server in the seed list). This functionality can be turned off by applications if desired and we'll drop this feature in the next major version.

Generated at Thu Feb 08 08:22:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.