{"action":"created","issue":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/5660","repository_url":"https://api.github.com/repos/rethinkdb/rethinkdb","labels_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/5660/labels{/name}","comments_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/5660/comments","events_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/5660/events","html_url":"https://github.com/rethinkdb/rethinkdb/issues/5660","id":148141387,"number":5660,"title":"Java Driver: Connection is lost during changes(), never times out.","user":{"login":"mschurr","id":3498024,"avatar_url":"https://avatars.githubusercontent.com/u/3498024?v=3","gravatar_id":"","url":"https://api.github.com/users/mschurr","html_url":"https://github.com/mschurr","followers_url":"https://api.github.com/users/mschurr/followers","following_url":"https://api.github.com/users/mschurr/following{/other_user}","gists_url":"https://api.github.com/users/mschurr/gists{/gist_id}","starred_url":"https://api.github.com/users/mschurr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mschurr/subscriptions","organizations_url":"https://api.github.com/users/mschurr/orgs","repos_url":"https://api.github.com/users/mschurr/repos","events_url":"https://api.github.com/users/mschurr/events{/privacy}","received_events_url":"https://api.github.com/users/mschurr/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/labels/Java","name":"Java","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/milestones/119","html_url":"https://github.com/rethinkdb/rethinkdb/milestones/2.3.x","labels_url":"https://api.github.com/repos/rethinkdb/rethinkdb/milestones/119/labels","id":1687920,"number":119,"title":"2.3.x","description":null,"creator":{"login":"danielmewes","id":505365,"avatar_url":"https://avatars.githubusercontent.com/u/505365?v=3","gravatar_id":"","url":"https://api.github.com/users/danielmewes","html_url":"https://github.com/danielmewes","followers_url":"https://api.github.com/users/danielmewes/followers","following_url":"https://api.github.com/users/danielmewes/following{/other_user}","gists_url":"https://api.github.com/users/danielmewes/gists{/gist_id}","starred_url":"https://api.github.com/users/danielmewes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielmewes/subscriptions","organizations_url":"https://api.github.com/users/danielmewes/orgs","repos_url":"https://api.github.com/users/danielmewes/repos","events_url":"https://api.github.com/users/danielmewes/events{/privacy}","received_events_url":"https://api.github.com/users/danielmewes/received_events","type":"User","site_admin":false},"open_issues":51,"closed_issues":6,"state":"open","created_at":"2016-04-06T18:05:18Z","updated_at":"2016-04-15T01:56:05Z","due_on":null,"closed_at":null},"comments":5,"created_at":"2016-04-13T18:17:27Z","updated_at":"2016-04-15T09:50:28Z","closed_at":null,"body":"My code is essentially:\r\n\r\n```java\r\ntry (Connection conn = dbp.getConnection()) {\r\n  Cursor<HashMap<String, ?>> cursor = r.table(\"messages\").changes().run(conn);\r\n  for (HashMap<String, ?> item : cursor) {\r\n    .. do stuff ...\r\n  }\r\n}\r\n```\r\n\r\nI connected to the server and was successfully listening to changes. Then, I killed the database server (only a single instance was running). As far as I can tell, the Java driver does not break the for loop when the connection is lost it just keeps sitting there expecting more data forever. There doesn't appear to be any timeout period. And, obviously, if I restart the database server then changes don't start coming in again on that old cursor.\r\n\r\nSo my question is: how are we supposed to detect connection losses and recover from them if the driver just sits there in the loop?\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/comments/210394005","html_url":"https://github.com/rethinkdb/rethinkdb/issues/5660#issuecomment-210394005","issue_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/5660","id":210394005,"user":{"login":"mschurr","id":3498024,"avatar_url":"https://avatars.githubusercontent.com/u/3498024?v=3","gravatar_id":"","url":"https://api.github.com/users/mschurr","html_url":"https://github.com/mschurr","followers_url":"https://api.github.com/users/mschurr/followers","following_url":"https://api.github.com/users/mschurr/following{/other_user}","gists_url":"https://api.github.com/users/mschurr/gists{/gist_id}","starred_url":"https://api.github.com/users/mschurr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mschurr/subscriptions","organizations_url":"https://api.github.com/users/mschurr/orgs","repos_url":"https://api.github.com/users/mschurr/repos","events_url":"https://api.github.com/users/mschurr/events{/privacy}","received_events_url":"https://api.github.com/users/mschurr/received_events","type":"User","site_admin":false},"created_at":"2016-04-15T09:50:28Z","updated_at":"2016-04-15T09:50:28Z","body":"Sure, I have attached the debug logs. I inserted an item from the web UI before terminating the server and you can see that change shows up in the logs, so the change feed was working initially. The server was terminated roughly at `04:47:00`. I waited until roughly `04:57:00` (10 minutes) before capturing the logs - as you can see, nothing happened in the logs between when I terminated the server and then.\r\n\r\nThe logs:\r\n\r\n```\r\n04:45:31.251 [main] DEBUG d.SimpleTest - Channel opening...\r\n04:45:31.900 [main] DEBUG c.r.a.Query - JSON Send: Token: 1 [1,[152,[[15,[\"messages\"]]]],{\"db\":[14,[\"chatapp\"]]}]\r\n04:45:31.918 [pool-1-thread-1] DEBUG c.r.a.Query - JSON Recv: Token: 1 {\"t\":3,\"r\":[],\"n\":[1]}\r\n04:45:32.059 [main] DEBUG c.r.a.Query - JSON Send: Token: 1 [2]\r\n04:46:57.058 [pool-1-thread-1] DEBUG c.r.a.Query - JSON Recv: Token: 1 {\"t\":3,\"r\":[{\"new_val\":{\"id\":\"8a1ae685-ef92-4219-b053-6b0d06a8670f\",\"message\":\"Hello!\",\"name\":\"Bob\",\"time\":0},\"old_val\":null}],\"n\":[1]}\r\n04:46:57.065 [main] DEBUG d.SimpleTest - Channel received {new_val={name=Bob, id=8a1ae685-ef92-4219-b053-6b0d06a8670f, time=0, message=Hello!}, old_val=null}\r\n04:46:57.065 [main] DEBUG c.r.a.Query - JSON Send: Token: 1 [2]\r\n```\r\n\r\nThe complete code of my test:\r\n\r\n```java\r\npackage demo;\r\n\r\nimport static com.rethinkdb.RethinkDB.r;\r\n\r\nimport java.util.HashMap;\r\n\r\nimport org.slf4j.Logger;\r\nimport org.slf4j.LoggerFactory;\r\n\r\nimport com.rethinkdb.RethinkDB;\r\nimport com.rethinkdb.net.Connection;\r\nimport com.rethinkdb.net.Cursor;\r\n\r\npublic class SimpleTest {\r\n  private static final Logger logger = LoggerFactory.getLogger(SimpleTest.class);\r\n  \r\n  public static void main(String[] args) throws Exception {    \r\n    logger.debug(\"Channel opening...\");\r\n    try (Connection conn = \r\n        RethinkDB.r.connection().hostname(\"localhost\").port(28015).db(\"chatapp\").connect()) {\r\n      Cursor<HashMap<String, ?>> cursor = null;\r\n      try {\r\n        cursor = r.table(\"messages\").changes().run(conn);\r\n        \r\n        for (HashMap<String, ?> item : cursor) {\r\n          logger.debug(\"Channel received {}\", item);            \r\n        }\r\n      } finally {\r\n        if (cursor != null) {\r\n          cursor.close();\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n```"}}