PouchDB ETIMEDOUT error

2019-07-11 04:01发布

问题:

So we've been building an app that uses couchDb/cloudant with Pouchdb as our driver client side (ionic framework) and server side (node).

Of late we've been getting errors when connecting to the remote, that seem to appear at random and only disappear temporarily restarting the app, or opening a new browser.

update-data.service.js:38 Error: ETIMEDOUT(…)(anonymous function) @ update-data.service.js:38processQueue @ angular.js:16383(anonymous function) @ angular.js:16399$eval @ angular.js:17682$digest @ angular.js:17495(anonymous function) @ angular.js:17721completeOutstandingRequest @ angular.js:5964(anonymous function) @ angular.js:6243

When running in incognito browser though temporarily removed the issue (or seperate browser) but the error always comes back.

Starting and stopping couch seems to also temporarily solve the problem.

Issue comes up unpredictably when running as an app (both android and ios) with cloudant as the backend

Have not seen it yet on node.js server.

Any possible avenues or directions that we could explore?

回答1:

I have these ETIMEDOUT errors from PouchDB when the HTTP request to a remote database cannot be done, presumably because of a poor internet connection.

If there is up and downs in your connection you can try to increase the duration before a timeout error is thrown (see the options for remote databases in the doc):

var remote = new PouchDB('address', {
  ajax: {
    timeout: 60000,
  }
});

In the above example, a timeout error will be thrown only if the HTTP request cannot be done for 60 seconds.