-
Type: Question
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
What is the expected behaviour of the connectTimeoutMS option for mongo URI's against tools like mongodump?
I notice that with 3.6 to 4.0 this option behaves in seconds on a CentOS7 box when attempting to connect to a non-existent mongodb server:
mongo 3.6:
[kcheung@kingsley-centos99 scripts]$ mongodump --version
mongodump version: r3.6.14
git version: cbef87692475857c7ee6e764c8f5104b39c342a1
Go version: go1.11.9
os: linux
arch: amd64
compiler: gc
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
[kcheung@kingsley-centos99 scripts]$ time /usr/bin/mongodump --uri mongodb://localhost:3011/meteor?connectTimeoutMS=10
2020-01-16T18:29:26.584+1100 Failed: error connecting to db server: no reachable servers
real 0m11.566s
user 0m0.015s
sys 0m0.024s
mongo 4.0:
[root@0bba8d73ecdf yum.repos.d]# mongodump --version
mongodump version: r4.0.14
git version: 1622021384533dade8b3c89ed3ecd80e1142c132
Go version: go1.11.13
os: linux
arch: amd64
compiler: gc
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
[root@0bba8d73ecdf yum.repos.d]# time /usr/bin/mongodump --uri mongodb://localhost:3011/meteor?connectTimeoutMS=5
2020-01-16T07:12:02.300+0000 Failed: error connecting to db server: no reachable servers
real 0m5.548s
user 0m0.009s
sys 0m0.020s
However, from mongo 4.2 onwards the timeout is now hard-coded to 30 seconds:
[root@0bba8d73ecdf yum.repos.d]# mongodump --version
mongodump version: r4.2.2
git version: a0bbbff6ada159e19298d37946ac8dc4b497eadf
Go version: go1.12.13
os: linux
arch: amd64
compiler: gc
[root@0bba8d73ecdf yum.repos.d]# time /usr/bin/mongodump --uri mongodb://localhost:3011/meteor?connectTimeoutMS=5
2020-01-16T07:17:32.618+0000 Failed: can't create session: could not connect to server: server selection error: server selection timeout
current topology: Type: Single
Servers:
Addr: localhost:3011, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection(localhost:3011[-121]) connection is closed
real 0m30.007s
user 0m0.156s
sys 0m0.509s
[root@0bba8d73ecdf yum.repos.d]# time /usr/bin/mongodump --uri mongodb://localhost:3011/meteor?connectTimeoutMS=40000
2020-01-16T07:18:07.604+0000 Failed: can't create session: could not connect to server: server selection error: server selection timeout
current topology: Type: Single
Servers:
Addr: localhost:3011, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection(localhost:3011[-121]) connection is closed
real 0m30.010s
user 0m0.217s
sys 0m0.413s