Regression in pull of blobs/legacy attachment handling
Description
CBL 3.0.0+ is mishandling blobs on pull from Sync Gateway. It is trying to fetch attachments from blobs in the document, even if Sync Gateway sent no attachment metadata with the document revision. CBL should always be acting on the contents of `_attachments` when replicating with Sync Gateway, and never inline blobs, as per: https://github.com/couchbase/couchbase-lite-core/wiki/Legacy-Attachment-Handling#pulling-from-sync-gateway This may differ for CBL P2P, where both peers understand blobs.
Attachment vs. Blob background:
Sync Gateway does not support blobs! Only top-level `_attachments`. CBL performs the necessary incantations to translate document blobs into these attachments during replication in both directions.
From Sync Gateway's point of view, `_attachments` is the source of truth for what attachments exist on a document.
If nothing is in `_attachments`, there are no attachments **}}and will actively delete attachment data{{** when an attachment digest is dereferenced in this way.
Setup (any CBL version):
1. Empty Bucket 2. Create SG database
3. Create user
4. Create document with blob in CBL
(in example/logs Doc ID `2f8a18a0-3780-4616-8320-77e6002e9b48` Rev ID `1-1abd4365f119b400300e3405a24f058f7795c62f`) 5. Push to SG 6. Remove attachment in SG
7. See doc now with no attachments via SG:
Since SG doesn't know what blobs are, and doesn't care that "myblob" remains in the document body... The `_attachments` property and internal metadata for attachments are now empty
Repro/Regression description:
Need new empty CBL database to pull this document into (the bug requires the client to be pulling the new revision but also whilst it doesn't have the blob)
CBL 2.8.6 identifies that the doc no longer has an attachment and doesn't try to pull it.
CBL 3.0.0 thinks because it sees a blob, the doc must have an attachment, and tries to pull a non-existent attachment, which fails.
Repro Steps:
1. Create a new CBL database 2. Start a pull replication
Expected (2.8.6):
Doc pulled without error (and no attachment/blob fetch attempted)
Actual (in 3.0.0+)
Doc pulled but not stored - got 403 error trying to pull a non-existent attachment
Another potential bug, the client appears to checkpoint past the failed document?
Activity
Show:
Florian Kelbert June 7, 2024 at 6:03 AM
is there any chance to get this backported to CBL 3.1 branch? This is causing significant production impact for one user.
CB robot March 9, 2024 at 12:46 AM
Build couchbase-lite-c-3.2.0-34 contains couchbase-lite-core commit 984c633 with commit message: : Handling blobs that reference attachments that are already deleted in SG. (#1885) (#1917)
CB robot February 2, 2024 at 5:57 PM
Build couchbase-lite-ios-3.2.0-55 contains couchbase-lite-core commit 984c633 with commit message: : Handling blobs that reference attachments that are already deleted in SG. (#1885) (#1917)
CB robot January 15, 2024 at 9:42 PM
Build couchbase-lite-cblite-3.2.0-20 contains couchbase-lite-core commit 984c633 with commit message: : Handling blobs that reference attachments that are already deleted in SG. (#1885) (#1917)
CB robot January 15, 2024 at 7:44 PM
Build couchbase-lite-log-3.2.0-19 contains couchbase-lite-core commit 984c633 with commit message: : Handling blobs that reference attachments that are already deleted in SG. (#1885) (#1917)
Fixed
Pinned fields
Click on the next to a field label to start pinning.
CBL 3.0.0+ is mishandling blobs on pull from Sync Gateway. It is trying to fetch attachments from blobs in the document, even if Sync Gateway sent no attachment metadata with the document revision.
CBL should always be acting on the contents of `
_attachments
` when replicating with Sync Gateway, and never inline blobs, as per: https://github.com/couchbase/couchbase-lite-core/wiki/Legacy-Attachment-Handling#pulling-from-sync-gatewayThis may differ for CBL P2P, where both peers understand blobs.
Attachment vs. Blob background:
Sync Gateway does not support blobs! Only top-level `
_attachments
`. CBL performs the necessary incantations to translate document blobs into these attachments during replication in both directions.From Sync Gateway's point of view, `
_attachments
` is the source of truth for what attachments exist on a document.If nothing is in `
_attachments
`, there are no attachments **}}and will actively delete attachment data{{*
* when an attachment digest is dereferenced in this way.Setup (any CBL version):
1. Empty Bucket
2. Create SG database
3. Create user
4. Create document with blob in CBL
(in example/logs Doc ID `
2f8a18a0-3780-4616-8320-77e6002e9b48
` Rev ID `1-1abd4365f119b400300e3405a24f058f7795c62f
`)5. Push to SG
6. Remove attachment in SG
7. See doc now with no attachments via SG:
Since SG doesn't know what blobs are, and doesn't care that "myblob" remains in the document body... The `
_attachments
` property and internal metadata for attachments are now emptyRepro/Regression description:
Need new empty CBL database to pull this document into (the bug requires the client to be pulling the new revision but also whilst it doesn't have the blob)
CBL 2.8.6 identifies that the doc no longer has an attachment and doesn't try to pull it.
CBL 3.0.0 thinks because it sees a blob, the doc must have an attachment, and tries to pull a non-existent attachment, which fails.
Repro Steps:
1. Create a new CBL database
2. Start a pull replication
Expected (2.8.6):
Doc pulled without error (and no attachment/blob fetch attempted)
Actual (in 3.0.0+)
Doc pulled but not stored - got 403 error trying to pull a non-existent attachment
Another potential bug, the client appears to checkpoint past the failed document?