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

Advancing a new command cursor to check for an error may invoke getMore

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 1.3.3
    • Fix Version/s: 1.4.0-RC1, 1.4.0
    • Component/s: None
    • Labels:
      None

      Description

      When phongo_execute_command() calls phongo_advance_cursor_and_check_for_error() after constructing a command cursor from the envelope response, the ensuing mongoc_cursor_next() is prone to causing a getMore if the firstBatch in the original response is empty. This can be seen with traditional command cursors (e.g. aggregate) and tailable command cursors (e.g. aggregate with $changeStream), although the issue is more pronounced with tailable command cursors as the first getMore may block for one second (default await time).

      The phongo_advance_cursor_and_check_for_error() call was introduced in 18e2e2d for PHPC-602. Looking at the history of that commit, it appears a call to next() is necessary to advance the cursor to the first document in the command cursor reply. Removing this call causes several tests to fail, as the cursor is never advanced to its first element and the valid iteration handler likely returns false. We should investigate if it's possible to delay this advance to the cursor's rewind handler.

      Today, it's not actually necessary to call the rewind handler to iterate a cursor (demonstrated if we wrap a Cursor with an IteratorIterator and manually iterate). We should also see if that behavior can be preserved.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: