-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Unknown
-
None
-
Affects Version/s: 1.23.1
-
Component/s: libmongoc
Summary
Destruction of "topology->server_monitors" can take up to 500ms, as the server is making a blocking heartbeat poll that cannot be canceled for 500ms (MONGOC_TOPOLOGY_MIN_HEARTBEAT_FREQUENCY_MS).
That makes mongoc quite slow to run in unit tests, as every case takes around 500ms.
Environment
Driver Versions 1.21.0-1.22.2. Probably older versions too.
System: Ubuntu 20.04 x64 and Windows 10 x64.
Compiler: GCC 9.3.0 and MSBuild v141.
Server version: 4.4.12.
How to Reproduce
- Initialize mongoc driver;
- Create mongoc client pool;
- Connect to MongoDB using the pool;
- Destroy the pool.
Actual result: mongoc_client_pool_destroy takes 500ms.
Additional Background
It looks like the heartbeat implemented in the way that client sends the heartbeat to the server and then relies on the server to send response in10 seconds, but not later than in 20 seconds. While waiting for the server's response the client polls the socket with 500ms intervals. Those intervals are blocking and cannot be cancelled. And there is no way to set heartbeat interval less than 500ms (Error parsing URI: 'Invalid "heartbeatfrequencyms" of 1: must be at least 500').
I feel like there should be an option to either cancel the poll, or make it much smaller if we want to keep it blocking.