Uploaded image for project: 'Couchbase Gateway'
  1. Couchbase Gateway
  2. CBG-2055

Mutating a document with an attachment on over CBL causes the attachment to be deleted from the bucket

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Critical
    • 3.0.3
    • 3.0.0
    • SyncGateway
    • Security Level: Public
    • CBG Sprint 98
    • 5

    Description

      Couchbase Lite 3.0.0 and 2.8.6 (and possibly versions below) have a bug where an attachment revpos on a stub is always the document revision. This means that Sync Gateway receives the wrong revpos for a document attachment when the document is mutated which causes SGW to remove it from the bucket, as the old attachment cannot be found and therefore is assumed to be an obsolete attachment.

      Reproduction steps using CBL

      1. Create a document with an attachment on it
      2. Start a continuous replication to the sync gateway
      3. When that document has replicated, modify it on CBL by adding a key
      4. Wait for that to replicate to the sync gateway
      5. Check bucket that the attachment has disappeared

      Sync Gateways pathing that is causing this

      1. The version is being added when the initial document with the attachment is being created. This is done in storeAttachment
      2. The next mutation of the document causes SGW to go in to the stub handling code in storeAttachment. A parent attachment is successfully retrieved, but because the revpos is not lower than the first revision, the parent attachment does not replace the attachment data causing the attachment version (v2) to be lost (and the revpos).
      3. When the rev processing is done in handleRev then processRev, the leaf attachments cannot be found in getAttachmentIDsForLeafRevisions since the attachment is treated as a v1 attachment (since the attachment is lost), meaning it is not found. This causes no attachments to be found, so therefore the obsolete attachment handling thinks it is an attachment no longer attached to the document causing the attachment to be removed from the bucket.

      What needs to be done

      An incorrect revpos sent by CBL that is caused by this bug needs to be handled gracefully by treating the attachment as valid and, most importantly, not deleting the attachment from the bucket.

      Attachments

        Issue Links

          Activity

            People

              adamf Adam Fraser
              isaac.lambat Isaac Lambat
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                PagerDuty