{"action":"created","issue":{"url":"https://api.github.com/repos/pouchdb/pouchdb/issues/4541","labels_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/4541/labels{/name}","comments_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/4541/comments","events_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/4541/events","html_url":"https://github.com/pouchdb/pouchdb/issues/4541","id":114947426,"number":4541,"title":"Better handling of live replication and changes requests","user":{"login":"garethbowen","id":2064938,"avatar_url":"https://avatars.githubusercontent.com/u/2064938?v=3","gravatar_id":"","url":"https://api.github.com/users/garethbowen","html_url":"https://github.com/garethbowen","followers_url":"https://api.github.com/users/garethbowen/followers","following_url":"https://api.github.com/users/garethbowen/following{/other_user}","gists_url":"https://api.github.com/users/garethbowen/gists{/gist_id}","starred_url":"https://api.github.com/users/garethbowen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garethbowen/subscriptions","organizations_url":"https://api.github.com/users/garethbowen/orgs","repos_url":"https://api.github.com/users/garethbowen/repos","events_url":"https://api.github.com/users/garethbowen/events{/privacy}","received_events_url":"https://api.github.com/users/garethbowen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-11-04T01:18:17Z","updated_at":"2015-11-04T19:26:08Z","closed_at":null,"body":"I'm using replication with `{ live:true }` over http which makes a request for the `_changes` feed with the following parameters:\r\n\r\nParameter | Value\r\n-------------- | ----------\r\ntimeout | 25000\r\nfeed | longpoll\r\nheartbeat | 10000\r\nstyle | all_docs\r\nfilter | my_filter\r\nsince | 5195\r\nlimit | 100\r\n_nonce | 1446598600731\r\n\r\nThen exactly 30 seconds later that request gets cancelled and I get this error in the console:\r\n\r\n```\r\nUncaught (in promise) e {status: 500, name: \"unknown_error\", message: \"Database encountered an unknown error\", error: true, result: Object}\r\n```\r\n\r\nIn the couchdb [changes docs](https://couchdb.readthedocs.org/en/1.6.1/api/database/changes.html) it says\r\n\r\n> heartbeat ... Overrides any timeout to keep the feed alive indefinitely.\r\n\r\nI think what's happening here is the `timeout` parameter is being ignored by couch and the request is being kept alive until it's killed by pouch at 30 seconds. I guess this is the desired behaviour but there are a few things that could be done to improve this.\r\n\r\n1. Catch the \"unknown error\" so it doesn't look like a bug.\r\n2. Don't send the timeout parameter if it'll be ignored. This is very minor but makes the request easier to understand.\r\n3. Don't cancel the request if using a heartbeat. The whole point of the heartbeat is to keep the connection alive so cancelling it manually seems counterproductive.\r\n\r\nThis applies to both the replication and changes apis.\r\n"},"comment":{"url":"https://api.github.com/repos/pouchdb/pouchdb/issues/comments/153837914","html_url":"https://github.com/pouchdb/pouchdb/issues/4541#issuecomment-153837914","issue_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/4541","id":153837914,"user":{"login":"garethbowen","id":2064938,"avatar_url":"https://avatars.githubusercontent.com/u/2064938?v=3","gravatar_id":"","url":"https://api.github.com/users/garethbowen","html_url":"https://github.com/garethbowen","followers_url":"https://api.github.com/users/garethbowen/followers","following_url":"https://api.github.com/users/garethbowen/following{/other_user}","gists_url":"https://api.github.com/users/garethbowen/gists{/gist_id}","starred_url":"https://api.github.com/users/garethbowen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garethbowen/subscriptions","organizations_url":"https://api.github.com/users/garethbowen/orgs","repos_url":"https://api.github.com/users/garethbowen/repos","events_url":"https://api.github.com/users/garethbowen/events{/privacy}","received_events_url":"https://api.github.com/users/garethbowen/received_events","type":"User","site_admin":false},"created_at":"2015-11-04T19:26:08Z","updated_at":"2015-11-04T19:26:08Z","body":"I can replicate with Chromium 45 and Firefox 41. I've looked at the code a little more and I think you're right, specifying a timeout on the changes feed will work. I'm still stuck with replication because of #4540 .\r\n\r\nI think the low priority points 1 and 2 still stand. Another potential improvement is for changes and replication apis to not use the default the timeout when doing live replication. This will help it work as expected out of the box."}}