Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-786

Using w=-1 write concern causes "invalid response_to" cursor errors

    • Type: Icon: Task Task
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 1.2-beta0
    • Component/s: libmongoc
    • None

      While testing multiple write concerns in sequence (e.g. w=-1, followed by w=0, and then w=1) via the PHP driver, I encountered the following exception:

      Invalid response_to. Expected 4, got 2.

      I traced this back to mongoc-cursor.c:

      if (cursor->rpc.header.response_to != request_id) {
         bson_set_error (&cursor->error,
                         MONGOC_ERROR_PROTOCOL,
                         MONGOC_ERROR_PROTOCOL_INVALID_REPLY,
                         "Invalid response_to. Expected %d, got %d.",
                         request_id, cursor->rpc.header.response_to);
         GOTO (failure);
      }
      

      ...in both _mongoc_cursor_query() and _mongoc_cursor_get_more(). In my case (performing writes), it was the former function triggering the error.

      I understand why this error occurs, since w=-1 instructs the driver to return to the application before reading any response on the wire. It's fundamentally incompatible with write commands, since those always yield a server response; however, I'm curious if the driver should be consuming old responses to w=-1 writes in lieu of raising cursor reply errors.

      Offhand, I didn't find any mention of this in the write command specification, although I have some recollection of this (specifically w=-1) being discussed in the past.

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

              Created:
              Updated:
              Resolved: