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

executeBulkWrite() may leave dangling session pointer on BulkWrite object

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.9.0-rc1, 1.9.0
    • Affects Version/s: 1.4.0
    • Component/s: None
    • None

      If an explicit session (i.e. "session" option) is provided to phongo_execute_bulk_write(), the underlying libmongoc client session is assigned to the mongoc_bulk_operation_t object with mongoc_bulk_operation_set_client_session(). This sets the session pointer on the mongoc_bulk_operation_t struct, which is only ever accessed by mongoc_bulk_operation_execute(), which we call later in phongo_execute_bulk_write().

      Since we prohibit executing BulkWrite objects multiple times, we can trust that the session will always correspond to the correct libmongoc client and that the mongoc_client_session_destroy() is never called between mongoc_bulk_operation_set_client_session() and mongoc_bulk_operation_execute(). Even if the incoming "session" option had only a single reference (e.g. ["session" => $manager->startSession()]), it would exist for the duration of the executeBulkWrite() method call before the object is cleaned up by php_phongo_session_free_object() and mongoc_client_session_destroy() is called.

      That said, we are still technically leaving a dangling pointer on the the mongoc_bulk_operation_t object contained within the BulkWrite object. Unfortunately, mongoc_bulk_operation_set_client_session() does not allow us to reset the session to NULL, so addressing this may require us to track a reference to the Session object on the BulkWrite object as it is executed. This would be comparable to what was done for Cursors in PHPC-1151.

            Assignee:
            andreas.braun@mongodb.com Andreas Braun
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: