Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1947

Subscription to cluster events leads to new connection pool created

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.2
    • Component/s: Configuration
    • Labels:
      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

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            sapostol sergii
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: