6

While trying to integrate couchbase mobile (version 1.1.0) in our hybrid mobile app (ionic), we ran into an issue with the push replication on iOS.

At some point in the application (after the local database has been created and so on) a design document with some views is created successfully. A continuous push and pull replication is created and started as well.

When polling for the push replication status we noticed that it had stopped (not normal for a continous replication) shortly after it had been started.

Couchbase mobile replied with an error (404)

WARNING: CBL_Pusher[http://server:4985/bucket-sync-gateway]: _bulk_docs got an error: {
   error = "bad_request";
   id = "_design/app";
   reason = "Invalid doc ID";
   status = 400;
}

The sync gateway logged a similar error:

BulkDocs: Doc "_design/app" --> 400 Invalid doc ID (400 Invalid doc ID)

This only happens on iOS. The android version doesn't have issues with the replications (maybe the design documents are ignored?)

  • Why does the replication try to sync design documents on ios and not on android?
  • Should design documents be synched?
  • Is there a way to prevent certain document of being synched? (Native api's provide a filtering mechanism on replications, but the rest-api does not)

Any idea what could be the problem here?

Cheers,

Bert

Bert
  • 257
  • 1
  • 2
  • 10

1 Answers1

2

Which versions of Couchbase Lite and Sync Gateway are you using? I believe the behavior has improved in version 1.1 of each. Specifically, Sync Gateway now returns 403 Forbidden instead of 400 Bad Request when a client attempts to upload a design document. The Couchbase Lite replicator will keep going after this status instead of stopping with an error.

Design documents are problematic since they usually contain executable (JavaScript) code in the form of map, reduce or filter functions. For security reasons Sync Gateway (like CouchDB) won't allow a non-admin client to upload one.

Worse, it is probably a violation of your Apple developer agreement to have your iOS app download a design doc, since apps aren't allowed to execute downloaded code. (The reason I say "probably" is because the exception is JavaScript code running in a web browser. The design doc does contain JS, and your PhoneGap app code does run in a browser, but the map/reduce/filter functions run not in the browser but in a separate JS context invoked by Couchbase Lite. I am not a lawyer and I have no idea what Apple would think of that. To my knowledge it's never come up.)

—Jens Alfke (Mobile Architect, Couchbase)

Jens Alfke
  • 1,946
  • 12
  • 15
  • Thank you for the warnings about Apple's petty rules. – chicks Jun 26 '15 at 18:28
  • Heh. I wouldn't say they're "petty" — the rules make sense from a security standpoint since they eliminate a wide variety of remote-code-execution vulnerabilities from buggy interpreters (like Flash.) "Overly strict" perhaps. – Jens Alfke Jun 29 '15 at 00:41
  • Hi Jens, we're using couchbase lite 1.1 and sync gateway 1.0.4-34. We'll try the new sync gateway first. Will let u know how that goes. Thanks for the tip! – Bert Jun 29 '15 at 06:46
  • The same error still occurrs when using version 1.1 for both couchbase lite and the sync gateway (the replicator still stops with a bad request error) – Bert Jun 29 '15 at 10:57
  • Is there a way to exclude design documents from being pushed to the sync server? – Bert Jun 30 '15 at 06:51
  • We managed to get the sync working by using the normal user port instead of the admin port (were using that for dev purposes) for sync gateway communication. – Bert Jun 30 '15 at 08:30
  • @Bert, I suggest [filing an issue against Sync Gateway](https://github.com/couchbase/sync_gateway/issues/new). I tried a PUT to a design-doc URL and got a 403, but it may be that when it's uploaded as part of a bulk_docs call it still returns 400. – Jens Alfke Jun 30 '15 at 18:48
  • Oops, forgot that the Return key ends a comment! Also meant to say that you can use a replication filter to prevent a design doc from being pushed. – Jens Alfke Jun 30 '15 at 18:49