Search code examples
couchdbcloudflarepouchdb

524 response has no CORS headers


I have a Couch/Pouch app that seems to work correctly, but suffers strange delays and fills the browser log with CORS errors. The CORS errors only occur on timed out GETs, because their responses don't supply CORS headers.

Using browser dev tools I can see many successful polling requests that look like this:

GET https://couch.server/mydb/_changes
  ?style=all_docs
  &filter=_view
  &view=visible/person
  &since=369-69pI ...... bTC_376CZ
  &limit=100
               response 200

... and a bad one like this ...

OPTIONS https://couch.server/mydb/_changes
  ?style=all_docs
  &feed=longpoll
  &heartbeat=10000
  &filter=_view
  &view=visible/person
  &since=369-69pI ...... bTC_376CZ
  &limit=100
               response 200

GET https://couch.server/mydb/_changes
  ?style=all_docs
  &feed=longpoll
  &heartbeat=10000
  &filter=_view
  &view=visible/person
  &since=369-69pI ...... bTC_376CZ
  &limit=100
               response 524

So there are just two differences between the good case and the bad case. In the bad case PouchDB:

  1. precedes the GET request with an OPTIONS request
  2. specifies a longpoll feed with a 10 second timeout

The defect, apparently, is that CouchDB's 524 response has no CORS headers!

I have four such live: true, retry: true replicators, so my browser logs are showing four red-inked errors every ten seconds.

I would post this as an issue in CouchDB repository, but I wanted some feedback here first; I could easily be misunderstanding something,

Other factors:

  1. I host the client code in GitHub pages and serve it through CloudFlare.
  2. Access to CouchDB from clients also goes through CloudFlare
  3. CouchDB sits behind NGinx on my VPS.

Let me know if there are further details I should be providing, please.


Solution

  • Credit for answering this question should actually go to @sideshowbarker, since he made me realize that the error was not in CouchDB but in my Cloudflare settings.

    In those settings I had my CouchDB site set to use DNS and HTTP proxy (CDN) (orange cloud icon) mode rather then DNS only (grey cloud icon). Switching to DNS only and, perhaps unnecessarily, wiping the cache, solved the problem after a considerable delay (over an hour?).