-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.4.2
-
Component/s: Configuration
-
None
I am working on Web API project that should be hosted on azure environment. I would like to log commands execution time and details per web request. To make it possible I subscribe to CommandStartedEvent, CommandSucceededEvent and CommandFailedEvent events that give me all necessary information. But as I should link mongo command to web request I have to create new MongoClient per web request and subscribe to events for every new MongoClient. As result mongo driver create new connection pool for every new MongoClient. On Azure environment amount of opened tcp connections is limited so my application start to response with mongo timeout exception just after few second being under load.
After digging into source code of mongo driver I found that clusters are cached in ClusterRegistry based on ClusterKey. (internal ICluster GetOrCreateCluster(ClusterKey clusterKey)). But overloaded of method Equals of ClusterKey compares references of Actions (object.ReferenceEquals(_clusterConfigurator, rhs._clusterConfigurator)) what is almost impossible to achieve under real circumstances.
I would propose to move events subscription to MongoClient level so different clients would be able to share single MongoCluster but still receive events notification separately