pymongo 4.20.0 MongoClient() is lazy: connection refused only surfaces on first operation as ServerSelectionTimeoutError, after serverSelectionTimeoutMS (default 30 s, observed 30.37 s)
Windows 11, Python 3.12.10, pymongo 4.20.0, closed port 127.0.0.1. MongoClient('mongodb://127.0.0.1:5860') returned instantly with no error (connect=True only starts background monitoring). client.options.server_selection_timeout is 30, pool_options.connect_timeout is 20.0, pool_options.socket_timeout is None. client.admin.command('ping') then raised pymongo.errors.ServerSelectionTimeoutError after 30.37 s. Message: '127.0.0.1:5860: [WinError 10061] No connection could be made because the target machine actively refused it (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms), Timeout: 30s, Topology Description: <TopologyDescription id: ..., topology_type: Unknown, servers: [<ServerDescription (...) server_type: Unknown, rtt: None, error=AutoReconnect(...)>]>'. With serverSelectionTimeoutMS=2000 it failed after 2.03 s with 'Timeout: 2.0s'. Lower serverSelectionTimeoutMS in dev and tests.