Push replication is corrupting attachment in memory, can't read content once this happens

Using CBLite.NET 1.4.1

I’ve come across a scenario where an attachment on a document is being corrupted in memory, and I’ve narrowed the problem down to the push replication. Once the attachment is corrupted, our application must be restarted, and then the attachment can be loaded again. No physical corruption or data loss is occurring, as far as I can tell.

When a document with an attachment is saved, the push replication kicks off and attempts to upload the revision. During this process, the application code attempts to read the attachment again from the document. The attachment content returned by CBLite is null and the following error is logged:

2018-03-30 23:51:25,967 [19796] WARN : [DATABASE (AttachmentInternal)] Unable to decode attachment!

I’ve stepped through the CBLite source, and a normal attachment contains 5 metadata properties which are passed into the Attachment constructor:

  • content_type
  • digest
  • length
  • revpos
  • sub

When the corruption happens, and the application code calls “Document.CurrentRevision.GetAttachment(name)”, only 2 metadata properties are passed into the Attachment constructor:

  • stub
  • revpos

At this point, the Attachment.Content property returns null.

Creating a new revision of the document appears to “fix” the issue, because a new call to GetAttachment succeeds. But, it is immediately corrupted by the pusher, so it’s not really a viable work around.

No pull replication is running when this happens. The push is continuous.

I don’t have it in front of me, but I remember “MutateAttachments” being in the call stack.

@jens, @borrrden: Any ideas?