Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-1161

Free reference to Session once Cursor is exhausted

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.4.3
    • Affects Version/s: None
    • Component/s: None
    • None

      Per the Server Session spec:

      An implicit session MUST be returned to the pool immediately following the completion of an operation. When an implicit session is associated with a cursor for use with getMore operations, the session MUST be returned to the pool immediately following a getMore operation that indicates that the cursor has been exhausted. In particular, it MUST not wait until all documents have been iterated by the application or until the application disposes of the cursor. For language runtimes that provide the ability to attach finalizers to objects that are run prior to garbage collection, the cursor class SHOULD return an implicit session to the pool in the finalizer if the cursor has not already been exhausted.

      PHPC-1151 added a reference to Sessions on the Cursor object to ensure that the underlying libmongoc client session is kept active for all cursor-related operations (e.g. getMore, killCursors). PHPC-1152 adds emulation of implicit sessions in executeCommand() (similar to what CDRIVER-2578 did for change streams) to ensure that a command cursor shares the same session as its originating command.

      As a result of these changes, we should ensure that the Cursor's reference to its Session is freed as soon as we observe that that cursor ID is zero. At that point, we know that the server's results have been exhausted (the cursor is closed) and the driver will neither issue another getMore nor attempt to kill the cursor during cleanup.

      This is somewhat related to PHPC-1120 and its dependency CDRIVER-2503; however, those issues relate purely to libmongoc's own implicit sessions. With respect to PHPC, that pertains to executeQuery() and executeBulkWrite() only once PHPC-1152 has been implemented.

            Assignee:
            jmikola@mongodb.com Jeremy Mikola
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: