{"action":"created","comment":{"url":"https://api.github.com/repos/grpc/grpc-java/pulls/comments/35470948","id":35470948,"diff_hunk":"@@ -438,37 +450,30 @@ private void onError(ErrorCode errorCode, String moreDetail) {\n \n   private void onGoAway(int lastKnownStreamId, Status status) {\n     boolean notifyShutdown;\n-    ArrayList<OkHttpClientStream> goAwayStreams = new ArrayList<OkHttpClientStream>();\n-    List<PendingStream> pendingStreamsCopy;\n     synchronized (lock) {\n       notifyShutdown = !goAway;\n       goAway = true;\n       goAwayStatus = status;\n-      synchronized (streams) {\n-        Iterator<Map.Entry<Integer, OkHttpClientStream>> it = streams.entrySet().iterator();\n-        while (it.hasNext()) {\n-          Map.Entry<Integer, OkHttpClientStream> entry = it.next();\n-          if (entry.getKey() > lastKnownStreamId) {\n-            goAwayStreams.add(entry.getValue());\n-            it.remove();\n-          }\n+      Iterator<Map.Entry<Integer, OkHttpClientStream>> it = streams.entrySet().iterator();\n+      while (it.hasNext()) {\n+        Map.Entry<Integer, OkHttpClientStream> entry = it.next();\n+        if (entry.getKey() > lastKnownStreamId) {\n+          entry.getValue().transportReportStatus(status, false, new Metadata.Trailers());\n+          it.remove();\n         }\n       }\n-      pendingStreamsCopy = pendingStreams;\n-      pendingStreams = new LinkedList<PendingStream>();\n+\n+      for (PendingStream stream : pendingStreams) {\n+        stream.clientStream.transportReportStatus(status, true, new Metadata.Trailers());\n+        stream.createdFuture.set(null);\n+      }\n+      pendingStreams.clear();\n     }\n \n     if (notifyShutdown) {\n       listener.transportShutdown();","path":"okhttp/src/main/java/io/grpc/transport/okhttp/OkHttpClientTransport.java","position":null,"original_position":98,"commit_id":"12ada438374c8ff1f55d66f0f4550780155e7649","original_commit_id":"1cfded768daf90a6e209169237d52369941a2926","user":{"login":"madongfly","id":1962333,"avatar_url":"https://avatars.githubusercontent.com/u/1962333?v=3","gravatar_id":"","url":"https://api.github.com/users/madongfly","html_url":"https://github.com/madongfly","followers_url":"https://api.github.com/users/madongfly/followers","following_url":"https://api.github.com/users/madongfly/following{/other_user}","gists_url":"https://api.github.com/users/madongfly/gists{/gist_id}","starred_url":"https://api.github.com/users/madongfly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/madongfly/subscriptions","organizations_url":"https://api.github.com/users/madongfly/orgs","repos_url":"https://api.github.com/users/madongfly/repos","events_url":"https://api.github.com/users/madongfly/events{/privacy}","received_events_url":"https://api.github.com/users/madongfly/received_events","type":"User","site_admin":false},"body":"But calling a callback with holding a lock is risky.\r\n\r\nHow about move it inside the stopIfNecessary(), as:\r\n```\r\nvoid stopIfNecessary(boolean notifyShutdown) {\r\n     if (notifyShutdown) {\r\n       listener.transportShutdown();\r\n     }\r\n     synchronized (lock) {\r\n       ...\r\n     }\r\n}\r\n```\r\nAdded a TODO.","created_at":"2015-07-24T22:14:51Z","updated_at":"2015-07-24T22:14:51Z","html_url":"https://github.com/grpc/grpc-java/pull/667#discussion_r35470948","pull_request_url":"https://api.github.com/repos/grpc/grpc-java/pulls/667","_links":{"self":{"href":"https://api.github.com/repos/grpc/grpc-java/pulls/comments/35470948"},"html":{"href":"https://github.com/grpc/grpc-java/pull/667#discussion_r35470948"},"pull_request":{"href":"https://api.github.com/repos/grpc/grpc-java/pulls/667"}}},"pull_request":{"url":"https://api.github.com/repos/grpc/grpc-java/pulls/667","id":40801328,"html_url":"https://github.com/grpc/grpc-java/pull/667","diff_url":"https://github.com/grpc/grpc-java/pull/667.diff","patch_url":"https://github.com/grpc/grpc-java/pull/667.patch","issue_url":"https://api.github.com/repos/grpc/grpc-java/issues/667","number":667,"state":"open","locked":false,"title":"Simplify locking model of OkHttp Transport, avoid potential deadlock.","user":{"login":"madongfly","id":1962333,"avatar_url":"https://avatars.githubusercontent.com/u/1962333?v=3","gravatar_id":"","url":"https://api.github.com/users/madongfly","html_url":"https://github.com/madongfly","followers_url":"https://api.github.com/users/madongfly/followers","following_url":"https://api.github.com/users/madongfly/following{/other_user}","gists_url":"https://api.github.com/users/madongfly/gists{/gist_id}","starred_url":"https://api.github.com/users/madongfly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/madongfly/subscriptions","organizations_url":"https://api.github.com/users/madongfly/orgs","repos_url":"https://api.github.com/users/madongfly/repos","events_url":"https://api.github.com/users/madongfly/events{/privacy}","received_events_url":"https://api.github.com/users/madongfly/received_events","type":"User","site_admin":false},"body":"1. Remove the stream lock, use transport lock instead.\r\n2. Protected streams map with the transport lock instead of using synchronized map.\r\n\r\nFixes #583\r\n\r\n@ejona86 Please take a look, thanks!","created_at":"2015-07-24T18:17:02Z","updated_at":"2015-07-24T22:14:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"110e8b220a428deeaf223bec00a4d62f4ed4cddb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/grpc/grpc-java/pulls/667/commits","review_comments_url":"https://api.github.com/repos/grpc/grpc-java/pulls/667/comments","review_comment_url":"https://api.github.com/repos/grpc/grpc-java/pulls/comments{/number}","comments_url":"https://api.github.com/repos/grpc/grpc-java/issues/667/comments","statuses_url":"https://api.github.com/repos/grpc/grpc-java/statuses/12ada438374c8ff1f55d66f0f4550780155e7649","head":{"label":"madongfly:lock","ref":"lock","sha":"12ada438374c8ff1f55d66f0f4550780155e7649","user":{"login":"madongfly","id":1962333,"avatar_url":"https://avatars.githubusercontent.com/u/1962333?v=3","gravatar_id":"","url":"https://api.github.com/users/madongfly","html_url":"https://github.com/madongfly","followers_url":"https://api.github.com/users/madongfly/followers","following_url":"https://api.github.com/users/madongfly/following{/other_user}","gists_url":"https://api.github.com/users/madongfly/gists{/gist_id}","starred_url":"https://api.github.com/users/madongfly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/madongfly/subscriptions","organizations_url":"https://api.github.com/users/madongfly/orgs","repos_url":"https://api.github.com/users/madongfly/repos","events_url":"https://api.github.com/users/madongfly/events{/privacy}","received_events_url":"https://api.github.com/users/madongfly/received_events","type":"User","site_admin":false},"repo":{"id":32011307,"name":"grpc-java","full_name":"madongfly/grpc-java","owner":{"login":"madongfly","id":1962333,"avatar_url":"https://avatars.githubusercontent.com/u/1962333?v=3","gravatar_id":"","url":"https://api.github.com/users/madongfly","html_url":"https://github.com/madongfly","followers_url":"https://api.github.com/users/madongfly/followers","following_url":"https://api.github.com/users/madongfly/following{/other_user}","gists_url":"https://api.github.com/users/madongfly/gists{/gist_id}","starred_url":"https://api.github.com/users/madongfly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/madongfly/subscriptions","organizations_url":"https://api.github.com/users/madongfly/orgs","repos_url":"https://api.github.com/users/madongfly/repos","events_url":"https://api.github.com/users/madongfly/events{/privacy}","received_events_url":"https://api.github.com/users/madongfly/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/madongfly/grpc-java","description":"The Java gRPC implementation. HTTP/2 based RPC","fork":true,"url":"https://api.github.com/repos/madongfly/grpc-java","forks_url":"https://api.github.com/repos/madongfly/grpc-java/forks","keys_url":"https://api.github.com/repos/madongfly/grpc-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/madongfly/grpc-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/madongfly/grpc-java/teams","hooks_url":"https://api.github.com/repos/madongfly/grpc-java/hooks","issue_events_url":"https://api.github.com/repos/madongfly/grpc-java/issues/events{/number}","events_url":"https://api.github.com/repos/madongfly/grpc-java/events","assignees_url":"https://api.github.com/repos/madongfly/grpc-java/assignees{/user}","branches_url":"https://api.github.com/repos/madongfly/grpc-java/branches{/branch}","tags_url":"https://api.github.com/repos/madongfly/grpc-java/tags","blobs_url":"https://api.github.com/repos/madongfly/grpc-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/madongfly/grpc-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/madongfly/grpc-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/madongfly/grpc-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/madongfly/grpc-java/statuses/{sha}","languages_url":"https://api.github.com/repos/madongfly/grpc-java/languages","stargazers_url":"https://api.github.com/repos/madongfly/grpc-java/stargazers","contributors_url":"https://api.github.com/repos/madongfly/grpc-java/contributors","subscribers_url":"https://api.github.com/repos/madongfly/grpc-java/subscribers","subscription_url":"https://api.github.com/repos/madongfly/grpc-java/subscription","commits_url":"https://api.github.com/repos/madongfly/grpc-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/madongfly/grpc-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/madongfly/grpc-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/madongfly/grpc-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/madongfly/grpc-java/contents/{+path}","compare_url":"https://api.github.com/repos/madongfly/grpc-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/madongfly/grpc-java/merges","archive_url":"https://api.github.com/repos/madongfly/grpc-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/madongfly/grpc-java/downloads","issues_url":"https://api.github.com/repos/madongfly/grpc-java/issues{/number}","pulls_url":"https://api.github.com/repos/madongfly/grpc-java/pulls{/number}","milestones_url":"https://api.github.com/repos/madongfly/grpc-java/milestones{/number}","notifications_url":"https://api.github.com/repos/madongfly/grpc-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/madongfly/grpc-java/labels{/name}","releases_url":"https://api.github.com/repos/madongfly/grpc-java/releases{/id}","created_at":"2015-03-11T10:19:21Z","updated_at":"2015-04-29T23:27:25Z","pushed_at":"2015-07-24T22:09:05Z","git_url":"git://github.com/madongfly/grpc-java.git","ssh_url":"git@github.com:madongfly/grpc-java.git","clone_url":"https://github.com/madongfly/grpc-java.git","svn_url":"https://github.com/madongfly/grpc-java","homepage":"","size":3377,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":false,"has_wiki":false,"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":"grpc:master","ref":"master","sha":"eba12fb51489611b10ec40de467f2891199dff37","user":{"login":"grpc","id":7802525,"avatar_url":"https://avatars.githubusercontent.com/u/7802525?v=3","gravatar_id":"","url":"https://api.github.com/users/grpc","html_url":"https://github.com/grpc","followers_url":"https://api.github.com/users/grpc/followers","following_url":"https://api.github.com/users/grpc/following{/other_user}","gists_url":"https://api.github.com/users/grpc/gists{/gist_id}","starred_url":"https://api.github.com/users/grpc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grpc/subscriptions","organizations_url":"https://api.github.com/users/grpc/orgs","repos_url":"https://api.github.com/users/grpc/repos","events_url":"https://api.github.com/users/grpc/events{/privacy}","received_events_url":"https://api.github.com/users/grpc/received_events","type":"Organization","site_admin":false},"repo":{"id":27729926,"name":"grpc-java","full_name":"grpc/grpc-java","owner":{"login":"grpc","id":7802525,"avatar_url":"https://avatars.githubusercontent.com/u/7802525?v=3","gravatar_id":"","url":"https://api.github.com/users/grpc","html_url":"https://github.com/grpc","followers_url":"https://api.github.com/users/grpc/followers","following_url":"https://api.github.com/users/grpc/following{/other_user}","gists_url":"https://api.github.com/users/grpc/gists{/gist_id}","starred_url":"https://api.github.com/users/grpc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grpc/subscriptions","organizations_url":"https://api.github.com/users/grpc/orgs","repos_url":"https://api.github.com/users/grpc/repos","events_url":"https://api.github.com/users/grpc/events{/privacy}","received_events_url":"https://api.github.com/users/grpc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/grpc/grpc-java","description":"The Java gRPC implementation. HTTP/2 based RPC","fork":false,"url":"https://api.github.com/repos/grpc/grpc-java","forks_url":"https://api.github.com/repos/grpc/grpc-java/forks","keys_url":"https://api.github.com/repos/grpc/grpc-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/grpc/grpc-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/grpc/grpc-java/teams","hooks_url":"https://api.github.com/repos/grpc/grpc-java/hooks","issue_events_url":"https://api.github.com/repos/grpc/grpc-java/issues/events{/number}","events_url":"https://api.github.com/repos/grpc/grpc-java/events","assignees_url":"https://api.github.com/repos/grpc/grpc-java/assignees{/user}","branches_url":"https://api.github.com/repos/grpc/grpc-java/branches{/branch}","tags_url":"https://api.github.com/repos/grpc/grpc-java/tags","blobs_url":"https://api.github.com/repos/grpc/grpc-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/grpc/grpc-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/grpc/grpc-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/grpc/grpc-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/grpc/grpc-java/statuses/{sha}","languages_url":"https://api.github.com/repos/grpc/grpc-java/languages","stargazers_url":"https://api.github.com/repos/grpc/grpc-java/stargazers","contributors_url":"https://api.github.com/repos/grpc/grpc-java/contributors","subscribers_url":"https://api.github.com/repos/grpc/grpc-java/subscribers","subscription_url":"https://api.github.com/repos/grpc/grpc-java/subscription","commits_url":"https://api.github.com/repos/grpc/grpc-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/grpc/grpc-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/grpc/grpc-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/grpc/grpc-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/grpc/grpc-java/contents/{+path}","compare_url":"https://api.github.com/repos/grpc/grpc-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/grpc/grpc-java/merges","archive_url":"https://api.github.com/repos/grpc/grpc-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/grpc/grpc-java/downloads","issues_url":"https://api.github.com/repos/grpc/grpc-java/issues{/number}","pulls_url":"https://api.github.com/repos/grpc/grpc-java/pulls{/number}","milestones_url":"https://api.github.com/repos/grpc/grpc-java/milestones{/number}","notifications_url":"https://api.github.com/repos/grpc/grpc-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/grpc/grpc-java/labels{/name}","releases_url":"https://api.github.com/repos/grpc/grpc-java/releases{/id}","created_at":"2014-12-08T19:00:00Z","updated_at":"2015-07-24T18:47:06Z","pushed_at":"2015-07-24T22:09:06Z","git_url":"git://github.com/grpc/grpc-java.git","ssh_url":"git@github.com:grpc/grpc-java.git","clone_url":"https://github.com/grpc/grpc-java.git","svn_url":"https://github.com/grpc/grpc-java","homepage":"","size":19919,"stargazers_count":802,"watchers_count":802,"language":"Java","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":179,"mirror_url":null,"open_issues_count":86,"forks":179,"open_issues":86,"watchers":802,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/grpc/grpc-java/pulls/667"},"html":{"href":"https://github.com/grpc/grpc-java/pull/667"},"issue":{"href":"https://api.github.com/repos/grpc/grpc-java/issues/667"},"comments":{"href":"https://api.github.com/repos/grpc/grpc-java/issues/667/comments"},"review_comments":{"href":"https://api.github.com/repos/grpc/grpc-java/pulls/667/comments"},"review_comment":{"href":"https://api.github.com/repos/grpc/grpc-java/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/grpc/grpc-java/pulls/667/commits"},"statuses":{"href":"https://api.github.com/repos/grpc/grpc-java/statuses/12ada438374c8ff1f55d66f0f4550780155e7649"}}}}