{"action":"opened","issue":{"url":"https://api.github.com/repos/psycopg/psycopg2/issues/311","labels_url":"https://api.github.com/repos/psycopg/psycopg2/issues/311/labels{/name}","comments_url":"https://api.github.com/repos/psycopg/psycopg2/issues/311/comments","events_url":"https://api.github.com/repos/psycopg/psycopg2/issues/311/events","html_url":"https://github.com/psycopg/psycopg2/issues/311","id":71286090,"number":311,"title":"Connection object `closed` still zero after the [TCP/IP] connection is terminated","user":{"login":"amn","id":471489,"avatar_url":"https://avatars.githubusercontent.com/u/471489?v=3","gravatar_id":"","url":"https://api.github.com/users/amn","html_url":"https://github.com/amn","followers_url":"https://api.github.com/users/amn/followers","following_url":"https://api.github.com/users/amn/following{/other_user}","gists_url":"https://api.github.com/users/amn/gists{/gist_id}","starred_url":"https://api.github.com/users/amn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amn/subscriptions","organizations_url":"https://api.github.com/users/amn/orgs","repos_url":"https://api.github.com/users/amn/repos","events_url":"https://api.github.com/users/amn/events{/privacy}","received_events_url":"https://api.github.com/users/amn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-04-27T13:34:35Z","updated_at":"2015-04-27T13:34:35Z","closed_at":null,"body":"I have taken a look at the closely related issues [#263](https://github.com/psycopg/psycopg2/issues/263) and [#196](https://github.com/psycopg/psycopg2/issues/196).\r\n\r\nTested with psycopg2 2.6 as installed by `pip install psycopg2` in a virtual environment, on a CentOS 6.5, with Postgres 9.3 running on another host on the same network, also CentOS 6.5.\r\n\r\nDoing:\r\n\r\n```python\r\nimport psycopg2\r\nconn = psycopg2.connect(...)\r\ncur = conn.cursor()\r\ncur.execute('select 1')\r\n```\r\n\r\nAt which point I shutdown the remote Postgres server with a `service postgresql-9.3 stop`, and return to the above, typing:\r\n\r\n```python\r\nconn.closed\r\n```\r\n\r\n...which evaluates to `0`. I expect a closed connection and thus `1` instead. I also waited half an hour to see whether it was a lingering TCP/IP connection delaying necessary event(s) taking place, but it still got me `0` after all that time.\r\n\r\nI can do additional testing, if needed.\r\n\r\nI am going about this correctly, am I not? I just would like to somehow protect my client code from aborted connections, however these may manifest. Catching `OperationalError` exceptions is something I am a bit reluctant to do, as it would involve questionable heuristics that may not get me very far, in the long run.\r\n\r\nThank you."}}