{"action":"created","comment":{"url":"https://api.github.com/repos/agoragames/haigha/pulls/comments/31851889","id":31851889,"diff_hunk":"@@ -29,26 +34,33 @@ def connect(self, (host, port), klass=socket.socket):\n         Connect assuming a host and port tuple.\n         '''\n         self._host = \"%s:%s\" % (host, port)\n-        self._sock = klass()\n-        self._sock.setblocking(True)\n-        self._sock.settimeout(self.connection._connect_timeout)\n-        if self.connection._sock_opts:\n-            for k, v in self.connection._sock_opts.iteritems():\n-                family, type = k\n-                self._sock.setsockopt(family, type, v)\n-        infos = socket.getaddrinfo(host, port, 0, 0, socket.IPPROTO_TCP)\n-        exc = socket.error(\"getaddrinfo returns an empty list\")\n-        for _family, _socktype, _proto, _canonname, sockaddr in infos:\n+\n+        for info in socket.getaddrinfo(host, port, 0, 0, socket.IPPROTO_TCP):\n+\n+            family, socktype, proto, _, sockaddr = info\n+            self._sock = klass(family, socktype, proto)\n+            self._sock.setblocking(True)\n+            self._sock.settimeout(self.connection._connect_timeout)\n+            if self.connection._sock_opts:\n+                for k, v in self.connection._sock_opts.iteritems():\n+                    family, type = k\n+                    self._sock.setsockopt(family, type, v)\n             try:\n+\n                 self._sock.connect(sockaddr)\n-                break\n-            except socket.error as exc:\n+\n+            except Exception:\n+\n+                LOG.exception(\"Failed to connect to %s:\", sockaddr)\n                 continue\n+\n+            # After connecting, switch to full-blocking mode.\n+            self._sock.settimeout(None)\n+            break\n+\n         else:\n-            raise exc\n \n-        # After connecting, switch to full-blocking mode.\n-        self._sock.settimeout(None)\n+            raise ConnectionError(\"No valid socket object could be created.\")","path":"haigha/transports/socket_transport.py","position":63,"original_position":63,"commit_id":"66c27ddbf546e5c11da04e8d84a140e554cc438d","original_commit_id":"66c27ddbf546e5c11da04e8d84a140e554cc438d","user":{"login":"awestendorf","id":186921,"avatar_url":"https://avatars.githubusercontent.com/u/186921?v=3","gravatar_id":"","url":"https://api.github.com/users/awestendorf","html_url":"https://github.com/awestendorf","followers_url":"https://api.github.com/users/awestendorf/followers","following_url":"https://api.github.com/users/awestendorf/following{/other_user}","gists_url":"https://api.github.com/users/awestendorf/gists{/gist_id}","starred_url":"https://api.github.com/users/awestendorf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awestendorf/subscriptions","organizations_url":"https://api.github.com/users/awestendorf/orgs","repos_url":"https://api.github.com/users/awestendorf/repos","events_url":"https://api.github.com/users/awestendorf/events{/privacy}","received_events_url":"https://api.github.com/users/awestendorf/received_events","type":"User","site_admin":false},"body":"With the idea of raising the stdlib exceptions, could finish with simply:\r\n\r\n```python\r\nelse:\r\n    raise\r\n```\r\n\r\nThat only doesn't work if `getaddrinfo` returns an empty list, but I don't think there's a case for that.  However, if there is, then the need to raise `ConnectionError` in this one case might negate all my previous notes about raising the stdlib errors.  I don't feel particularly strongly either way.","created_at":"2015-06-05T21:09:49Z","updated_at":"2015-06-05T21:09:49Z","html_url":"https://github.com/agoragames/haigha/pull/69#discussion_r31851889","pull_request_url":"https://api.github.com/repos/agoragames/haigha/pulls/69","_links":{"self":{"href":"https://api.github.com/repos/agoragames/haigha/pulls/comments/31851889"},"html":{"href":"https://github.com/agoragames/haigha/pull/69#discussion_r31851889"},"pull_request":{"href":"https://api.github.com/repos/agoragames/haigha/pulls/69"}}},"pull_request":{"url":"https://api.github.com/repos/agoragames/haigha/pulls/69","id":31746891,"html_url":"https://github.com/agoragames/haigha/pull/69","diff_url":"https://github.com/agoragames/haigha/pull/69.diff","patch_url":"https://github.com/agoragames/haigha/pull/69.patch","issue_url":"https://api.github.com/repos/agoragames/haigha/issues/69","number":69,"state":"open","locked":false,"title":"Enforce two-tuple input for socket.connect()","user":{"login":"kevinconway","id":932395,"avatar_url":"https://avatars.githubusercontent.com/u/932395?v=3","gravatar_id":"","url":"https://api.github.com/users/kevinconway","html_url":"https://github.com/kevinconway","followers_url":"https://api.github.com/users/kevinconway/followers","following_url":"https://api.github.com/users/kevinconway/following{/other_user}","gists_url":"https://api.github.com/users/kevinconway/gists{/gist_id}","starred_url":"https://api.github.com/users/kevinconway/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevinconway/subscriptions","organizations_url":"https://api.github.com/users/kevinconway/orgs","repos_url":"https://api.github.com/users/kevinconway/repos","events_url":"https://api.github.com/users/kevinconway/events{/privacy}","received_events_url":"https://api.github.com/users/kevinconway/received_events","type":"User","site_admin":false},"body":"The results from `socket.getaddrinfo()` stored in `sockaddr` differ from IPv4 and IPv6. The IPv4 values are a two-tuple of (HOST, PORT). However, the IPv6 values are a four-tuple of (HOST, PORT, FLOW_INFO, SCOPE_ID). This behaviour is documented on https://docs.python.org/2/library/socket.html#socket.getaddrinfo. Unfortunately, the error thrown is not in the `socket.error` family which causes a stack trace rather than skipping the IPv6 connection.\r\n\r\nThe additional values returned for the IPv6 address are invalid for calls to `connect` which expects only a two-tuple matching the IPv4 output. There is an additional function in the socket modules, `create_connection`, which accounts for this issue. However, this function would not produce the correct socket implementation should one other than the standard lib be given.\r\n\r\nForcing the tuple length to two will cause the call to `connect` to raise an error in the `socket.error` family for IPv6 connections which, in turn, will cause the existing code to skip it and fall back on the IPv4 connection.","created_at":"2015-03-23T16:08:37Z","updated_at":"2015-06-05T21:09:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b91abe3d7d05ab150b2de8f49f8a675d6211ef5f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/agoragames/haigha/pulls/69/commits","review_comments_url":"https://api.github.com/repos/agoragames/haigha/pulls/69/comments","review_comment_url":"https://api.github.com/repos/agoragames/haigha/pulls/comments{/number}","comments_url":"https://api.github.com/repos/agoragames/haigha/issues/69/comments","statuses_url":"https://api.github.com/repos/agoragames/haigha/statuses/66c27ddbf546e5c11da04e8d84a140e554cc438d","head":{"label":"kevinconway:ipv6_socket","ref":"ipv6_socket","sha":"66c27ddbf546e5c11da04e8d84a140e554cc438d","user":{"login":"kevinconway","id":932395,"avatar_url":"https://avatars.githubusercontent.com/u/932395?v=3","gravatar_id":"","url":"https://api.github.com/users/kevinconway","html_url":"https://github.com/kevinconway","followers_url":"https://api.github.com/users/kevinconway/followers","following_url":"https://api.github.com/users/kevinconway/following{/other_user}","gists_url":"https://api.github.com/users/kevinconway/gists{/gist_id}","starred_url":"https://api.github.com/users/kevinconway/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevinconway/subscriptions","organizations_url":"https://api.github.com/users/kevinconway/orgs","repos_url":"https://api.github.com/users/kevinconway/repos","events_url":"https://api.github.com/users/kevinconway/events{/privacy}","received_events_url":"https://api.github.com/users/kevinconway/received_events","type":"User","site_admin":false},"repo":{"id":32742009,"name":"haigha","full_name":"kevinconway/haigha","owner":{"login":"kevinconway","id":932395,"avatar_url":"https://avatars.githubusercontent.com/u/932395?v=3","gravatar_id":"","url":"https://api.github.com/users/kevinconway","html_url":"https://github.com/kevinconway","followers_url":"https://api.github.com/users/kevinconway/followers","following_url":"https://api.github.com/users/kevinconway/following{/other_user}","gists_url":"https://api.github.com/users/kevinconway/gists{/gist_id}","starred_url":"https://api.github.com/users/kevinconway/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevinconway/subscriptions","organizations_url":"https://api.github.com/users/kevinconway/orgs","repos_url":"https://api.github.com/users/kevinconway/repos","events_url":"https://api.github.com/users/kevinconway/events{/privacy}","received_events_url":"https://api.github.com/users/kevinconway/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kevinconway/haigha","description":"AMQP Python client","fork":true,"url":"https://api.github.com/repos/kevinconway/haigha","forks_url":"https://api.github.com/repos/kevinconway/haigha/forks","keys_url":"https://api.github.com/repos/kevinconway/haigha/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kevinconway/haigha/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kevinconway/haigha/teams","hooks_url":"https://api.github.com/repos/kevinconway/haigha/hooks","issue_events_url":"https://api.github.com/repos/kevinconway/haigha/issues/events{/number}","events_url":"https://api.github.com/repos/kevinconway/haigha/events","assignees_url":"https://api.github.com/repos/kevinconway/haigha/assignees{/user}","branches_url":"https://api.github.com/repos/kevinconway/haigha/branches{/branch}","tags_url":"https://api.github.com/repos/kevinconway/haigha/tags","blobs_url":"https://api.github.com/repos/kevinconway/haigha/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kevinconway/haigha/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kevinconway/haigha/git/refs{/sha}","trees_url":"https://api.github.com/repos/kevinconway/haigha/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kevinconway/haigha/statuses/{sha}","languages_url":"https://api.github.com/repos/kevinconway/haigha/languages","stargazers_url":"https://api.github.com/repos/kevinconway/haigha/stargazers","contributors_url":"https://api.github.com/repos/kevinconway/haigha/contributors","subscribers_url":"https://api.github.com/repos/kevinconway/haigha/subscribers","subscription_url":"https://api.github.com/repos/kevinconway/haigha/subscription","commits_url":"https://api.github.com/repos/kevinconway/haigha/commits{/sha}","git_commits_url":"https://api.github.com/repos/kevinconway/haigha/git/commits{/sha}","comments_url":"https://api.github.com/repos/kevinconway/haigha/comments{/number}","issue_comment_url":"https://api.github.com/repos/kevinconway/haigha/issues/comments{/number}","contents_url":"https://api.github.com/repos/kevinconway/haigha/contents/{+path}","compare_url":"https://api.github.com/repos/kevinconway/haigha/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kevinconway/haigha/merges","archive_url":"https://api.github.com/repos/kevinconway/haigha/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kevinconway/haigha/downloads","issues_url":"https://api.github.com/repos/kevinconway/haigha/issues{/number}","pulls_url":"https://api.github.com/repos/kevinconway/haigha/pulls{/number}","milestones_url":"https://api.github.com/repos/kevinconway/haigha/milestones{/number}","notifications_url":"https://api.github.com/repos/kevinconway/haigha/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kevinconway/haigha/labels{/name}","releases_url":"https://api.github.com/repos/kevinconway/haigha/releases{/id}","created_at":"2015-03-23T15:47:35Z","updated_at":"2015-03-23T15:47:36Z","pushed_at":"2015-06-02T05:25:19Z","git_url":"git://github.com/kevinconway/haigha.git","ssh_url":"git@github.com:kevinconway/haigha.git","clone_url":"https://github.com/kevinconway/haigha.git","svn_url":"https://github.com/kevinconway/haigha","homepage":"","size":1751,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"agoragames:master","ref":"master","sha":"27510dbd09309c3eb8d73cf5cbcb40855eeef605","user":{"login":"agoragames","id":47092,"avatar_url":"https://avatars.githubusercontent.com/u/47092?v=3","gravatar_id":"","url":"https://api.github.com/users/agoragames","html_url":"https://github.com/agoragames","followers_url":"https://api.github.com/users/agoragames/followers","following_url":"https://api.github.com/users/agoragames/following{/other_user}","gists_url":"https://api.github.com/users/agoragames/gists{/gist_id}","starred_url":"https://api.github.com/users/agoragames/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agoragames/subscriptions","organizations_url":"https://api.github.com/users/agoragames/orgs","repos_url":"https://api.github.com/users/agoragames/repos","events_url":"https://api.github.com/users/agoragames/events{/privacy}","received_events_url":"https://api.github.com/users/agoragames/received_events","type":"Organization","site_admin":false},"repo":{"id":1238348,"name":"haigha","full_name":"agoragames/haigha","owner":{"login":"agoragames","id":47092,"avatar_url":"https://avatars.githubusercontent.com/u/47092?v=3","gravatar_id":"","url":"https://api.github.com/users/agoragames","html_url":"https://github.com/agoragames","followers_url":"https://api.github.com/users/agoragames/followers","following_url":"https://api.github.com/users/agoragames/following{/other_user}","gists_url":"https://api.github.com/users/agoragames/gists{/gist_id}","starred_url":"https://api.github.com/users/agoragames/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agoragames/subscriptions","organizations_url":"https://api.github.com/users/agoragames/orgs","repos_url":"https://api.github.com/users/agoragames/repos","events_url":"https://api.github.com/users/agoragames/events{/privacy}","received_events_url":"https://api.github.com/users/agoragames/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/agoragames/haigha","description":"AMQP Python client","fork":false,"url":"https://api.github.com/repos/agoragames/haigha","forks_url":"https://api.github.com/repos/agoragames/haigha/forks","keys_url":"https://api.github.com/repos/agoragames/haigha/keys{/key_id}","collaborators_url":"https://api.github.com/repos/agoragames/haigha/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/agoragames/haigha/teams","hooks_url":"https://api.github.com/repos/agoragames/haigha/hooks","issue_events_url":"https://api.github.com/repos/agoragames/haigha/issues/events{/number}","events_url":"https://api.github.com/repos/agoragames/haigha/events","assignees_url":"https://api.github.com/repos/agoragames/haigha/assignees{/user}","branches_url":"https://api.github.com/repos/agoragames/haigha/branches{/branch}","tags_url":"https://api.github.com/repos/agoragames/haigha/tags","blobs_url":"https://api.github.com/repos/agoragames/haigha/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/agoragames/haigha/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/agoragames/haigha/git/refs{/sha}","trees_url":"https://api.github.com/repos/agoragames/haigha/git/trees{/sha}","statuses_url":"https://api.github.com/repos/agoragames/haigha/statuses/{sha}","languages_url":"https://api.github.com/repos/agoragames/haigha/languages","stargazers_url":"https://api.github.com/repos/agoragames/haigha/stargazers","contributors_url":"https://api.github.com/repos/agoragames/haigha/contributors","subscribers_url":"https://api.github.com/repos/agoragames/haigha/subscribers","subscription_url":"https://api.github.com/repos/agoragames/haigha/subscription","commits_url":"https://api.github.com/repos/agoragames/haigha/commits{/sha}","git_commits_url":"https://api.github.com/repos/agoragames/haigha/git/commits{/sha}","comments_url":"https://api.github.com/repos/agoragames/haigha/comments{/number}","issue_comment_url":"https://api.github.com/repos/agoragames/haigha/issues/comments{/number}","contents_url":"https://api.github.com/repos/agoragames/haigha/contents/{+path}","compare_url":"https://api.github.com/repos/agoragames/haigha/compare/{base}...{head}","merges_url":"https://api.github.com/repos/agoragames/haigha/merges","archive_url":"https://api.github.com/repos/agoragames/haigha/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/agoragames/haigha/downloads","issues_url":"https://api.github.com/repos/agoragames/haigha/issues{/number}","pulls_url":"https://api.github.com/repos/agoragames/haigha/pulls{/number}","milestones_url":"https://api.github.com/repos/agoragames/haigha/milestones{/number}","notifications_url":"https://api.github.com/repos/agoragames/haigha/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/agoragames/haigha/labels{/name}","releases_url":"https://api.github.com/repos/agoragames/haigha/releases{/id}","created_at":"2011-01-10T15:46:13Z","updated_at":"2015-06-01T18:37:26Z","pushed_at":"2015-06-02T05:59:05Z","git_url":"git://github.com/agoragames/haigha.git","ssh_url":"git@github.com:agoragames/haigha.git","clone_url":"https://github.com/agoragames/haigha.git","svn_url":"https://github.com/agoragames/haigha","homepage":"","size":2403,"stargazers_count":103,"watchers_count":103,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":25,"mirror_url":null,"open_issues_count":28,"forks":25,"open_issues":28,"watchers":103,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/agoragames/haigha/pulls/69"},"html":{"href":"https://github.com/agoragames/haigha/pull/69"},"issue":{"href":"https://api.github.com/repos/agoragames/haigha/issues/69"},"comments":{"href":"https://api.github.com/repos/agoragames/haigha/issues/69/comments"},"review_comments":{"href":"https://api.github.com/repos/agoragames/haigha/pulls/69/comments"},"review_comment":{"href":"https://api.github.com/repos/agoragames/haigha/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/agoragames/haigha/pulls/69/commits"},"statuses":{"href":"https://api.github.com/repos/agoragames/haigha/statuses/66c27ddbf546e5c11da04e8d84a140e554cc438d"}}}}