Uploaded image for project: 'Drivers'
  1. Drivers
  2. DRIVERS-2647

Drivers should unpin connections when ending a session

    • Needed
    • Hide

      Summary of necessary driver changes

      •  Drivers must ensure that when running endSession that any pinned connection in load balancer mode is unpinned.
      • Sync the load balancer unified tests to the commit referenced below.

      Commits for syncing spec/prose tests
      (and/or refer to an existing language POC if needed)

      Context for other referenced/linked tickets

      •  
      Show
      Summary of necessary driver changes  Drivers must ensure that when running endSession that any pinned connection in load balancer mode is unpinned. Sync the load balancer unified tests to the commit referenced below. Commits for syncing spec/prose tests (and/or refer to an existing language POC if needed)   https://github.com/mongodb/specifications/commit/cbcf81bd04ea24fd2a7d8a77e19c75d426ca76b6 Context for other referenced/linked tickets  
    • $i18n.getText("admin.common.words.hide")
      Key Status/Resolution FixVersion
      CDRIVER-4756 Backlog
      CXX-2779 Backlog
      CSHARP-4829 Backlog
      GODRIVER-3034 Backlog
      JAVA-5228 Backlog
      NODE-5722 Done
      MOTOR-1204 Duplicate
      PYTHON-4020 Backlog
      PHPLIB-1299 Blocked
      RUBY-3343 Ready for Work
      RUST-1790 Backlog
      $i18n.getText("admin.common.words.show")
      #scriptField, #scriptField *{ border: 1px solid black; } #scriptField{ border-collapse: collapse; } #scriptField td { text-align: center; /* Center-align text in table cells */ } #scriptField td.key { text-align: left; /* Left-align text in the Key column */ } #scriptField a { text-decoration: none; /* Remove underlines from links */ border: none; /* Remove border from links */ } /* Add green background color to cells with FixVersion */ #scriptField td.hasFixVersion { background-color: #00FF00; /* Green color code */ } /* Center-align the first row headers */ #scriptField th { text-align: center; } Key Status/Resolution FixVersion CDRIVER-4756 Backlog CXX-2779 Backlog CSHARP-4829 Backlog GODRIVER-3034 Backlog JAVA-5228 Backlog NODE-5722 Done MOTOR-1204 Duplicate PYTHON-4020 Backlog PHPLIB-1299 Blocked RUBY-3343 Ready for Work RUST-1790 Backlog

      Summary

      The Transactions and Load Balancer specs together describe the process for "pinning" a connection to a ClientSession when connected to a load-balancer so that all transaction operations are sent to the same mongos. The Load Balancers spec also requires that drivers not use the pinned connection for other transactions concurrently

      Drivers MUST NOT use the same connection for two concurrent transactions run under different sessions from the same client.

      which drivers may implement by giving exclusive access to the pinned connection to the ClientSession.

      The When to unpin section in the Transactions spec enumerates the conditions when a connection should be unpinned from a ClientSession. However, the list doesn't specify unpinning when a ClientSession is explicitly ended with endSession.

      According to the When to unpin section, the following sequence of events may never lead to a connection being unpinned from a ClientSession, effectively creating a connection "leak":

      1. Start a ClientSession.
      2. Run startTransaction in the session.
      3. Run insertMany in the transaction.
      4. Run commitTransaction.
      5. Run endSession.

      We should amend the When to unpin section to explicitly require drivers to unpin connections from a ClientSession when endSession is called.

      Motivation

      Who is the affected end user?

      Users running transactions on load-balanced databases (e.g. Atlas Serverless or dedicated clusters connecting via a VPC private link).

      How does this affect the end user?

      Connections used to run transactions may never be returned to the connection pool, resulting in a connection leak. If the driver is configured with a max connection pool size (or using the default), the driver may eventually run out of unpinned connections and hang.

      How likely is it that this problem or use case will occur?

      If a driver unpins connections strictly as described in When to unpin in the Transactions spec, a connection leak will happen anytime a customer creates a session, runs a transaction, and ends the session while connected to a load-balanced database.

      Some drivers already unpin connections when ending sessions and are unaffected.

      If the problem does occur, what are the consequences and how severe are they?

      A driver will either open and then then not use many extra connections or it will hang and stop working.

      Is this issue urgent?

      The issue in the Go driver (GODRIVER-2867) is moderately urgent because it is the root cause of a mongosync bug that is blocking a customer migration (HELP-46291). Its urgency depends on how many other drivers are impacted by the problem and the rate of adoption of impacted services, like Serverless. Overall, it seems moderately urgent to figure out how many drivers are impacted.

      Is this ticket required by a downstream team?

      No.

      Is this ticket only for tests?

      No.

      Acceptance Criteria

      • Amend the "When to unpin" section of the Transactions spec to explicitly require drivers to unpin connections from a ClientSession when endSession is called.
      • Add a load balancer spec test that asserts that pinned connections are returned to the connection pool when endSession is called.

            Assignee:
            durran.jordan@mongodb.com Durran Jordan
            Reporter:
            matt.dale@mongodb.com Matt Dale
            Jeffrey Yemin Jeffrey Yemin
            Votes:
            1 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: