Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Database encountered an unknown error" during replication on IOS #40

Open
kripper opened this issue Jan 6, 2016 · 8 comments
Open

Comments

@kripper
Copy link

kripper commented Jan 6, 2016

Pouchdb 5.1 is failing to replicate on IOS with error:

{\"status\":500,\"name\":\"unknown_error\",\"message\":\"Database encountered an unknown error\"}"

I also get this CORS warning:

"PouchDB: the remote database may not have CORS enabled.If not please enable CORS: http://pouchdb.com/errors.html#no_access_control_allow_origin_header"

AFAIU, there shouldn't be CORS warnings since I'm using:

<access origin="*" />

Besides, other databases are pulled without errors (though they were reading and writing 0 docs).

I'm using PhoneGap with this user agent:

Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257 (400210848)

Same code works fine on Android, Chrome on Desktop.

Any hint?
Should I try an older version?
I'm using jsconsole and can run commands and do tests directly on the iPhone if necessary to debug.

@kripper
Copy link
Author

kripper commented Jan 6, 2016

I tested Safari on IOS and got the same error.

@kripper
Copy link
Author

kripper commented Jan 6, 2016

I tested Safari on Windows and also get the same error.
I confirmed that sometimes replication works fine for the same databases that other times failed.
Besides, I saw another error I'm not sure if it is related:
ReferenceError: Can't find variable: WebKitBlobBuilder
This is probably triggered because we have some docs with blob attachements.

@kripper
Copy link
Author

kripper commented Jan 7, 2016

I found out that the error is occurring because of the blob attachments.
When I disable the replication of this particular DB containing blob attachments, everything works fine.
Any workaround to use blobs on IOS?

@kripper
Copy link
Author

kripper commented Jan 7, 2016

The exception that is thrown by new Blob(parts, properties) in createBlob() is:

"'[object BlobConstructor]' is not a constructor (evaluating 'new Blob(parts, properties)')"

@kripper
Copy link
Author

kripper commented Jan 7, 2016

:-(

Disabling the replication of the DB with the blob attachment fixed the problem on Safary for Windows (which was throwing the same error as on IOS)...but I'm still getting the error on PhoneGap for IOS and Safary for IOS.

So, we have two issues here:

  1. Replication of blobs are failing on Safary for Windows and Safary for IOS and PhoneGap for IOS. This causes "Database encountered an unknown error" for this and subsequent replications.
    When disabling the replication of the DB with blobs, replication works at least on Safary for Windows, but NOT on Safary for IOS and PhoneGap for IOS.

  2. Safary for IOS and PhoneGap for IOS causes "Database encountered an unknown error", even when not replicating blobs.

@kripper
Copy link
Author

kripper commented Jan 7, 2016

Turned out that the app was doing concurrent replication (pulls) of the same database. This was causing the error on Safari and IOS, but not on Android.
I would suggest to detect this situation on Pouch's side (even when it's the users fault, it will save anyone's time and avoid users reporting bugs caused by race conditions ).
To solve, I added a flag on the pouch database object to prevent replicating twice while another replication is going on for the same DB.
There are many other reported issues regarding the "Database encountered an unknown error" message which could be related to this problem.

@kripper
Copy link
Author

kripper commented Jan 7, 2016

BTW, blobs are still generating an error when they are pulled on Safaty for Windows, Safari for IOS and PhoneGap for IOS (works fine on Android and Chrome).
But they are pushed correctly on PhoneGap for IOS.

@nolanlawson
Copy link
Member

Hmm, I'm not really understanding what's going on here. Do you have a reproducible test case?

I do know that there's a bug in iOS Safari WebView due to file:// URLs. Maybe you're hitting that: #11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants