{"action":"created","comment":{"url":"https://api.github.com/repos/uber/tchannel-python/pulls/comments/37026916","id":37026916,"diff_hunk":"@@ -540,121 +551,100 @@ def send(\n                 name=endpoint,\n                 trace_id=trace_id,\n                 parent_span_id=parent_span_id,\n-                endpoint=Endpoint(self.peer.host,\n-                                  self.peer.port,\n-                                  self.service),\n+                endpoint=Endpoint(peer.host, peer.port, self.service),\n                 traceflags=traceflag,\n             )\n         )\n \n         # only retry on non-stream request\n         if request.is_streaming_request or self._hostport:\n-            attempt_times = 1\n+            retry_limit = 1\n \n         if request.is_streaming_request:\n             request.ttl = 0\n \n-        # event: send_request\n-        self.peer.tchannel.event_emitter.fire(\n-            EventType.before_send_request,\n-            request,\n-        )\n-\n         try:\n             response = yield self.send_with_retry(\n-                request, peer, attempt_times\n-            )\n-        except ProtocolError as protocol_error:\n-            # event: after_receive_protocol_error\n-            self.peer.tchannel.event_emitter.fire(\n-                EventType.after_receive_error,\n-                request,\n-                protocol_error,\n+                request, peer, retry_limit, connection\n             )\n-            raise\n         except Exception as e:\n-            # event: on_operational_error\n-            self.peer.tchannel.event_emitter.fire(\n-                EventType.on_exception,\n-                request,\n-                e,\n+            # event: on_exception\n+            self.tchannel.event_emitter.fire(\n+                EventType.on_exception, request, e,\n             )\n             raise\n \n         log.debug(\"Got response %s\", response)\n-        # event: after_receive_response\n-        self.peer.tchannel.event_emitter.fire(\n-            EventType.after_receive_response,\n-            request,\n-            response,\n-        )\n \n         raise gen.Return(response)\n \n     @gen.coroutine\n     def _send(self, connection, req):\n+        # event: send_request\n+        self.tchannel.event_emitter.fire(EventType.before_send_request, req)\n         response_future = connection.send_request(req)\n+\n         with timeout(response_future, req.ttl):\n-            response = yield response_future\n+            try:\n+                response = yield response_future\n+            except ProtocolError as protocol_error:","path":"tchannel/tornado/peer.py","position":243,"original_position":243,"commit_id":"478bcf72f9d3c9600903c16e6595d05d90afc617","original_commit_id":"85d1f08fbf7c142454a61d5cc946fc3ff5e14153","user":{"login":"junchaowu","id":3731781,"avatar_url":"https://avatars.githubusercontent.com/u/3731781?v=3","gravatar_id":"","url":"https://api.github.com/users/junchaowu","html_url":"https://github.com/junchaowu","followers_url":"https://api.github.com/users/junchaowu/followers","following_url":"https://api.github.com/users/junchaowu/following{/other_user}","gists_url":"https://api.github.com/users/junchaowu/gists{/gist_id}","starred_url":"https://api.github.com/users/junchaowu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/junchaowu/subscriptions","organizations_url":"https://api.github.com/users/junchaowu/orgs","repos_url":"https://api.github.com/users/junchaowu/repos","events_url":"https://api.github.com/users/junchaowu/events{/privacy}","received_events_url":"https://api.github.com/users/junchaowu/received_events","type":"User","site_admin":false},"body":"Currently ProtocolError represent Error frames we received from network. We use code to know the specific error message. We will make different Errors though","created_at":"2015-08-13T21:19:59Z","updated_at":"2015-08-13T21:19:59Z","html_url":"https://github.com/uber/tchannel-python/pull/112#discussion_r37026916","pull_request_url":"https://api.github.com/repos/uber/tchannel-python/pulls/112","_links":{"self":{"href":"https://api.github.com/repos/uber/tchannel-python/pulls/comments/37026916"},"html":{"href":"https://github.com/uber/tchannel-python/pull/112#discussion_r37026916"},"pull_request":{"href":"https://api.github.com/repos/uber/tchannel-python/pulls/112"}}},"pull_request":{"url":"https://api.github.com/repos/uber/tchannel-python/pulls/112","id":42315614,"html_url":"https://github.com/uber/tchannel-python/pull/112","diff_url":"https://github.com/uber/tchannel-python/pull/112.diff","patch_url":"https://github.com/uber/tchannel-python/pull/112.patch","issue_url":"https://api.github.com/repos/uber/tchannel-python/issues/112","number":112,"state":"open","locked":false,"title":"retry refactor (3)","user":{"login":"junchaowu","id":3731781,"avatar_url":"https://avatars.githubusercontent.com/u/3731781?v=3","gravatar_id":"","url":"https://api.github.com/users/junchaowu","html_url":"https://github.com/junchaowu","followers_url":"https://api.github.com/users/junchaowu/followers","following_url":"https://api.github.com/users/junchaowu/following{/other_user}","gists_url":"https://api.github.com/users/junchaowu/gists{/gist_id}","starred_url":"https://api.github.com/users/junchaowu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/junchaowu/subscriptions","organizations_url":"https://api.github.com/users/junchaowu/orgs","repos_url":"https://api.github.com/users/junchaowu/repos","events_url":"https://api.github.com/users/junchaowu/events{/privacy}","received_events_url":"https://api.github.com/users/junchaowu/received_events","type":"User","site_admin":false},"body":"Several major changes on this diff.\r\n1. move the peer select logic to the 'send' method. Whenever tchannel calls send, it will pick a new peer based on current peers and connections. Before we have a fix peer assigned to the peerclientoperation class. We may be in trouble that the peer is no long healthy but the peerclientoperation instance still uses it. It also makes more sense on the retry logic.\r\n2. Refactor events emit code. Previously we will have a potential bug that we record an send_request event, but due to retry happening, the response that we finally received is not matched to the first request. Because during retry, after we switch to a new peer and a new connection, the request's id, connection host, port (used in the tracing) will become different. (sorry terrible explanation, it will be better explain with code) \r\n3. Optimized retry code a bit. Retry workarounds.","created_at":"2015-08-13T05:10:26Z","updated_at":"2015-08-13T21:19:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b1df26836697eee5b7f2568b95188f5710a986e2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/uber/tchannel-python/pulls/112/commits","review_comments_url":"https://api.github.com/repos/uber/tchannel-python/pulls/112/comments","review_comment_url":"https://api.github.com/repos/uber/tchannel-python/pulls/comments{/number}","comments_url":"https://api.github.com/repos/uber/tchannel-python/issues/112/comments","statuses_url":"https://api.github.com/repos/uber/tchannel-python/statuses/478bcf72f9d3c9600903c16e6595d05d90afc617","head":{"label":"uber:retry","ref":"retry","sha":"478bcf72f9d3c9600903c16e6595d05d90afc617","user":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"repo":{"id":38906603,"name":"tchannel-python","full_name":"uber/tchannel-python","owner":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber/tchannel-python","description":"Python implementation of the TChannel protocol.","fork":false,"url":"https://api.github.com/repos/uber/tchannel-python","forks_url":"https://api.github.com/repos/uber/tchannel-python/forks","keys_url":"https://api.github.com/repos/uber/tchannel-python/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber/tchannel-python/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber/tchannel-python/teams","hooks_url":"https://api.github.com/repos/uber/tchannel-python/hooks","issue_events_url":"https://api.github.com/repos/uber/tchannel-python/issues/events{/number}","events_url":"https://api.github.com/repos/uber/tchannel-python/events","assignees_url":"https://api.github.com/repos/uber/tchannel-python/assignees{/user}","branches_url":"https://api.github.com/repos/uber/tchannel-python/branches{/branch}","tags_url":"https://api.github.com/repos/uber/tchannel-python/tags","blobs_url":"https://api.github.com/repos/uber/tchannel-python/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber/tchannel-python/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber/tchannel-python/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber/tchannel-python/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber/tchannel-python/statuses/{sha}","languages_url":"https://api.github.com/repos/uber/tchannel-python/languages","stargazers_url":"https://api.github.com/repos/uber/tchannel-python/stargazers","contributors_url":"https://api.github.com/repos/uber/tchannel-python/contributors","subscribers_url":"https://api.github.com/repos/uber/tchannel-python/subscribers","subscription_url":"https://api.github.com/repos/uber/tchannel-python/subscription","commits_url":"https://api.github.com/repos/uber/tchannel-python/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber/tchannel-python/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber/tchannel-python/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber/tchannel-python/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber/tchannel-python/contents/{+path}","compare_url":"https://api.github.com/repos/uber/tchannel-python/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber/tchannel-python/merges","archive_url":"https://api.github.com/repos/uber/tchannel-python/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber/tchannel-python/downloads","issues_url":"https://api.github.com/repos/uber/tchannel-python/issues{/number}","pulls_url":"https://api.github.com/repos/uber/tchannel-python/pulls{/number}","milestones_url":"https://api.github.com/repos/uber/tchannel-python/milestones{/number}","notifications_url":"https://api.github.com/repos/uber/tchannel-python/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber/tchannel-python/labels{/name}","releases_url":"https://api.github.com/repos/uber/tchannel-python/releases{/id}","created_at":"2015-07-10T23:35:17Z","updated_at":"2015-07-28T15:38:06Z","pushed_at":"2015-08-13T21:18:24Z","git_url":"git://github.com/uber/tchannel-python.git","ssh_url":"git@github.com:uber/tchannel-python.git","clone_url":"https://github.com/uber/tchannel-python.git","svn_url":"https://github.com/uber/tchannel-python","homepage":null,"size":3454,"stargazers_count":7,"watchers_count":7,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":22,"forks":1,"open_issues":22,"watchers":7,"default_branch":"master"}},"base":{"label":"uber:master","ref":"master","sha":"6220487b4494e9c7aad23b7f59b185569a15c482","user":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"repo":{"id":38906603,"name":"tchannel-python","full_name":"uber/tchannel-python","owner":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber/tchannel-python","description":"Python implementation of the TChannel protocol.","fork":false,"url":"https://api.github.com/repos/uber/tchannel-python","forks_url":"https://api.github.com/repos/uber/tchannel-python/forks","keys_url":"https://api.github.com/repos/uber/tchannel-python/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber/tchannel-python/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber/tchannel-python/teams","hooks_url":"https://api.github.com/repos/uber/tchannel-python/hooks","issue_events_url":"https://api.github.com/repos/uber/tchannel-python/issues/events{/number}","events_url":"https://api.github.com/repos/uber/tchannel-python/events","assignees_url":"https://api.github.com/repos/uber/tchannel-python/assignees{/user}","branches_url":"https://api.github.com/repos/uber/tchannel-python/branches{/branch}","tags_url":"https://api.github.com/repos/uber/tchannel-python/tags","blobs_url":"https://api.github.com/repos/uber/tchannel-python/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber/tchannel-python/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber/tchannel-python/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber/tchannel-python/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber/tchannel-python/statuses/{sha}","languages_url":"https://api.github.com/repos/uber/tchannel-python/languages","stargazers_url":"https://api.github.com/repos/uber/tchannel-python/stargazers","contributors_url":"https://api.github.com/repos/uber/tchannel-python/contributors","subscribers_url":"https://api.github.com/repos/uber/tchannel-python/subscribers","subscription_url":"https://api.github.com/repos/uber/tchannel-python/subscription","commits_url":"https://api.github.com/repos/uber/tchannel-python/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber/tchannel-python/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber/tchannel-python/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber/tchannel-python/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber/tchannel-python/contents/{+path}","compare_url":"https://api.github.com/repos/uber/tchannel-python/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber/tchannel-python/merges","archive_url":"https://api.github.com/repos/uber/tchannel-python/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber/tchannel-python/downloads","issues_url":"https://api.github.com/repos/uber/tchannel-python/issues{/number}","pulls_url":"https://api.github.com/repos/uber/tchannel-python/pulls{/number}","milestones_url":"https://api.github.com/repos/uber/tchannel-python/milestones{/number}","notifications_url":"https://api.github.com/repos/uber/tchannel-python/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber/tchannel-python/labels{/name}","releases_url":"https://api.github.com/repos/uber/tchannel-python/releases{/id}","created_at":"2015-07-10T23:35:17Z","updated_at":"2015-07-28T15:38:06Z","pushed_at":"2015-08-13T21:18:24Z","git_url":"git://github.com/uber/tchannel-python.git","ssh_url":"git@github.com:uber/tchannel-python.git","clone_url":"https://github.com/uber/tchannel-python.git","svn_url":"https://github.com/uber/tchannel-python","homepage":null,"size":3454,"stargazers_count":7,"watchers_count":7,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":22,"forks":1,"open_issues":22,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/uber/tchannel-python/pulls/112"},"html":{"href":"https://github.com/uber/tchannel-python/pull/112"},"issue":{"href":"https://api.github.com/repos/uber/tchannel-python/issues/112"},"comments":{"href":"https://api.github.com/repos/uber/tchannel-python/issues/112/comments"},"review_comments":{"href":"https://api.github.com/repos/uber/tchannel-python/pulls/112/comments"},"review_comment":{"href":"https://api.github.com/repos/uber/tchannel-python/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/uber/tchannel-python/pulls/112/commits"},"statuses":{"href":"https://api.github.com/repos/uber/tchannel-python/statuses/478bcf72f9d3c9600903c16e6595d05d90afc617"}}}}