{"action":"created","comment":{"url":"https://api.github.com/repos/nodejs/node/pulls/comments/68193707","id":68193707,"diff_hunk":"@@ -426,67 +426,53 @@ bool AgentImpl::OnInspectorHandshakeIO(inspector_socket_t* socket,\n   }\n }\n \n-// static\n-void AgentImpl::OnRemoteDataIO(uv_stream_t* stream,\n-                           ssize_t read,\n-                           const uv_buf_t* b) {\n-  inspector_socket_t* socket = static_cast<inspector_socket_t*>(stream->data);\n-  AgentImpl* agent = static_cast<AgentImpl*>(socket->data);\n-  Mutex::ScopedLock scoped_lock(agent->pause_lock_);\n+void AgentImpl::OnRemoteDataIO(inspector_socket_t* socket,\n+                               ssize_t read,\n+                               const uv_buf_t* buf) {\n+  Mutex::ScopedLock scoped_lock(pause_lock_);\n   if (read > 0) {\n-    std::string str(b->base, read);\n-    agent->PushPendingMessage(&agent->message_queue_, str);\n-    free(b->base);\n-\n+    String16 str = String16::fromUTF8(buf->base, read);\n+    free(buf->base);\n+    PostIncomingMessage(str);\n     // TODO(pfeldman): Instead of blocking execution while debugger\n     // engages, node should wait for the run callback from the remote client\n     // and initiate its startup. This is a change to node.cc that should be\n     // upstreamed separately.\n-    if (agent->wait_ && str.find(\"\\\"Runtime.run\\\"\") != std::string::npos) {\n-      agent->wait_ = false;\n-      uv_sem_post(&agent->start_sem_);\n+    if (wait_ && str.find(\"\\\"Runtime.run\\\"\") != std::string::npos) {\n+      wait_ = false;\n+      uv_sem_post(&start_sem_);\n     }\n \n-    agent->platform_->CallOnForegroundThread(agent->parent_env_->isolate(),\n-        new DispatchOnInspectorBackendTask(agent));\n-    agent->parent_env_->isolate()\n-        ->RequestInterrupt(InterruptCallback, agent);\n-    uv_async_send(&agent->data_written_);\n+    platform_->CallOnForegroundThread(parent_env_->isolate(),\n+        new DispatchOnInspectorBackendTask(this));\n+    parent_env_->isolate()->RequestInterrupt(InterruptCallback, this);\n+    uv_async_send(&data_written_);\n   } else if (read <= 0) {\n     // EOF\n-    if (agent->client_socket_ == socket) {\n-      agent->client_socket_ = nullptr;\n-      agent->platform_->CallOnForegroundThread(agent->parent_env_->isolate(),\n-          new SetConnectedTask(agent, false));\n-      uv_async_send(&agent->data_written_);\n+    if (client_socket_ == socket) {\n+      String16 message(TAG_DISCONNECT, sizeof(TAG_DISCONNECT) - 1);\n+      client_socket_ = nullptr;\n+      PostIncomingMessage(message);\n+      uv_async_send(&data_written_);\n     }\n     DisconnectAndDisposeIO(socket);\n   }\n-  agent->pause_cond_.Broadcast(scoped_lock);\n-}\n-\n-void AgentImpl::PushPendingMessage(std::vector<std::string>* queue,\n-                                   const std::string& message) {\n-  Mutex::ScopedLock scoped_lock(queue_lock_);\n-  queue->push_back(message);\n-}\n-\n-void AgentImpl::SwapBehindLock(std::vector<std::string> AgentImpl::*queue,\n-                               std::vector<std::string>* output) {\n-  Mutex::ScopedLock scoped_lock(queue_lock_);\n-  (this->*queue).swap(*output);\n+  pause_cond_.Broadcast(scoped_lock);\n }\n \n // static\n void AgentImpl::WriteCbIO(uv_async_t* async) {\n   AgentImpl* agent = static_cast<AgentImpl*>(async->data);\n   inspector_socket_t* socket = agent->client_socket_;\n   if (socket) {\n-    std::vector<std::string> outgoing_messages;\n-    agent->SwapBehindLock(&AgentImpl::outgoing_message_queue_,\n-                          &outgoing_messages);\n-    for (auto const& message : outgoing_messages)\n-      inspector_write(socket, message.c_str(), message.length());\n+    MessageQueue outgoing_messages;\n+    agent->SwapBehindLock(&agent->outgoing_message_queue_, &outgoing_messages);\n+    for (const std::pair<int, String16>& m : outgoing_messages) {","path":"src/inspector_agent.cc","position":233,"original_position":233,"commit_id":"4ec2db931909040a6c5353acb1581647837c9e7d","original_commit_id":"4ec2db931909040a6c5353acb1581647837c9e7d","user":{"login":"bnoordhuis","id":275871,"avatar_url":"https://avatars.githubusercontent.com/u/275871?v=3","gravatar_id":"","url":"https://api.github.com/users/bnoordhuis","html_url":"https://github.com/bnoordhuis","followers_url":"https://api.github.com/users/bnoordhuis/followers","following_url":"https://api.github.com/users/bnoordhuis/following{/other_user}","gists_url":"https://api.github.com/users/bnoordhuis/gists{/gist_id}","starred_url":"https://api.github.com/users/bnoordhuis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bnoordhuis/subscriptions","organizations_url":"https://api.github.com/users/bnoordhuis/orgs","repos_url":"https://api.github.com/users/bnoordhuis/repos","events_url":"https://api.github.com/users/bnoordhuis/events{/privacy}","received_events_url":"https://api.github.com/users/bnoordhuis/received_events","type":"User","site_admin":false},"body":"`MessageQueue::value_type& m` or just `auto& m`?","created_at":"2016-06-23T08:21:09Z","updated_at":"2016-06-23T08:21:09Z","html_url":"https://github.com/nodejs/node/pull/7271#discussion_r68193707","pull_request_url":"https://api.github.com/repos/nodejs/node/pulls/7271","_links":{"self":{"href":"https://api.github.com/repos/nodejs/node/pulls/comments/68193707"},"html":{"href":"https://github.com/nodejs/node/pull/7271#discussion_r68193707"},"pull_request":{"href":"https://api.github.com/repos/nodejs/node/pulls/7271"}}},"pull_request":{"url":"https://api.github.com/repos/nodejs/node/pulls/7271","id":73453491,"html_url":"https://github.com/nodejs/node/pull/7271","diff_url":"https://github.com/nodejs/node/pull/7271.diff","patch_url":"https://github.com/nodejs/node/pull/7271.patch","issue_url":"https://api.github.com/repos/nodejs/node/issues/7271","number":7271,"state":"open","locked":false,"title":"inspector: Put connect and disconnect events into message queue","user":{"login":"eugeneo","id":287917,"avatar_url":"https://avatars.githubusercontent.com/u/287917?v=3","gravatar_id":"","url":"https://api.github.com/users/eugeneo","html_url":"https://github.com/eugeneo","followers_url":"https://api.github.com/users/eugeneo/followers","following_url":"https://api.github.com/users/eugeneo/following{/other_user}","gists_url":"https://api.github.com/users/eugeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/eugeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eugeneo/subscriptions","organizations_url":"https://api.github.com/users/eugeneo/orgs","repos_url":"https://api.github.com/users/eugeneo/repos","events_url":"https://api.github.com/users/eugeneo/events{/privacy}","received_events_url":"https://api.github.com/users/eugeneo/received_events","type":"User","site_admin":false},"body":"<!--\r\nThank you for your pull request. Please review below requirements.\r\n\r\nIf this aims to fix a regression or you’re adding a feature, make sure you also\r\nwrite a test. If possible, include a benchmark that quantifies your changes.\r\n\r\nFinally, read through our contributors guide and make adjustments as necessary:\r\nhttps://github.com/nodejs/node/blob/master/CONTRIBUTING.md\r\n-->\r\n\r\n##### Checklist\r\n<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->\r\n\r\n- [x] `make -j4 test` (UNIX) or `vcbuild test nosign` (Windows) passes\r\n- [x] the commit message follows commit guidelines\r\n\r\n\r\n##### Affected core subsystem(s)\r\ninspector\r\n\r\n\r\n##### Description of change\r\nPutting connect and disconnect events into the message queue removes some unlikely race conditions. It also allows reusing the V8 interrupt when frontend connects to Node.js running an infinite loop.\r\n\r\n\r\nCC: @ofrobots \r\n","created_at":"2016-06-11T00:49:13Z","updated_at":"2016-06-23T08:21:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1bff1679e3f57e48c03541f529b236cc05a4dceb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nodejs/node/pulls/7271/commits","review_comments_url":"https://api.github.com/repos/nodejs/node/pulls/7271/comments","review_comment_url":"https://api.github.com/repos/nodejs/node/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nodejs/node/issues/7271/comments","statuses_url":"https://api.github.com/repos/nodejs/node/statuses/4ec2db931909040a6c5353acb1581647837c9e7d","head":{"label":"eugeneo:async-connect","ref":"async-connect","sha":"4ec2db931909040a6c5353acb1581647837c9e7d","user":{"login":"eugeneo","id":287917,"avatar_url":"https://avatars.githubusercontent.com/u/287917?v=3","gravatar_id":"","url":"https://api.github.com/users/eugeneo","html_url":"https://github.com/eugeneo","followers_url":"https://api.github.com/users/eugeneo/followers","following_url":"https://api.github.com/users/eugeneo/following{/other_user}","gists_url":"https://api.github.com/users/eugeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/eugeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eugeneo/subscriptions","organizations_url":"https://api.github.com/users/eugeneo/orgs","repos_url":"https://api.github.com/users/eugeneo/repos","events_url":"https://api.github.com/users/eugeneo/events{/privacy}","received_events_url":"https://api.github.com/users/eugeneo/received_events","type":"User","site_admin":false},"repo":{"id":54138097,"name":"node","full_name":"eugeneo/node","owner":{"login":"eugeneo","id":287917,"avatar_url":"https://avatars.githubusercontent.com/u/287917?v=3","gravatar_id":"","url":"https://api.github.com/users/eugeneo","html_url":"https://github.com/eugeneo","followers_url":"https://api.github.com/users/eugeneo/followers","following_url":"https://api.github.com/users/eugeneo/following{/other_user}","gists_url":"https://api.github.com/users/eugeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/eugeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eugeneo/subscriptions","organizations_url":"https://api.github.com/users/eugeneo/orgs","repos_url":"https://api.github.com/users/eugeneo/repos","events_url":"https://api.github.com/users/eugeneo/events{/privacy}","received_events_url":"https://api.github.com/users/eugeneo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/eugeneo/node","description":"Node.js JavaScript runtime :sparkles::turtle::rocket::sparkles:","fork":true,"url":"https://api.github.com/repos/eugeneo/node","forks_url":"https://api.github.com/repos/eugeneo/node/forks","keys_url":"https://api.github.com/repos/eugeneo/node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eugeneo/node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eugeneo/node/teams","hooks_url":"https://api.github.com/repos/eugeneo/node/hooks","issue_events_url":"https://api.github.com/repos/eugeneo/node/issues/events{/number}","events_url":"https://api.github.com/repos/eugeneo/node/events","assignees_url":"https://api.github.com/repos/eugeneo/node/assignees{/user}","branches_url":"https://api.github.com/repos/eugeneo/node/branches{/branch}","tags_url":"https://api.github.com/repos/eugeneo/node/tags","blobs_url":"https://api.github.com/repos/eugeneo/node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eugeneo/node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eugeneo/node/git/refs{/sha}","trees_url":"https://api.github.com/repos/eugeneo/node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eugeneo/node/statuses/{sha}","languages_url":"https://api.github.com/repos/eugeneo/node/languages","stargazers_url":"https://api.github.com/repos/eugeneo/node/stargazers","contributors_url":"https://api.github.com/repos/eugeneo/node/contributors","subscribers_url":"https://api.github.com/repos/eugeneo/node/subscribers","subscription_url":"https://api.github.com/repos/eugeneo/node/subscription","commits_url":"https://api.github.com/repos/eugeneo/node/commits{/sha}","git_commits_url":"https://api.github.com/repos/eugeneo/node/git/commits{/sha}","comments_url":"https://api.github.com/repos/eugeneo/node/comments{/number}","issue_comment_url":"https://api.github.com/repos/eugeneo/node/issues/comments{/number}","contents_url":"https://api.github.com/repos/eugeneo/node/contents/{+path}","compare_url":"https://api.github.com/repos/eugeneo/node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eugeneo/node/merges","archive_url":"https://api.github.com/repos/eugeneo/node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eugeneo/node/downloads","issues_url":"https://api.github.com/repos/eugeneo/node/issues{/number}","pulls_url":"https://api.github.com/repos/eugeneo/node/pulls{/number}","milestones_url":"https://api.github.com/repos/eugeneo/node/milestones{/number}","notifications_url":"https://api.github.com/repos/eugeneo/node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eugeneo/node/labels{/name}","releases_url":"https://api.github.com/repos/eugeneo/node/releases{/id}","deployments_url":"https://api.github.com/repos/eugeneo/node/deployments","created_at":"2016-03-17T17:30:32Z","updated_at":"2016-04-18T17:50:02Z","pushed_at":"2016-06-22T16:15:50Z","git_url":"git://github.com/eugeneo/node.git","ssh_url":"git@github.com:eugeneo/node.git","clone_url":"https://github.com/eugeneo/node.git","svn_url":"https://github.com/eugeneo/node","homepage":"https://nodejs.org","size":208597,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":7,"forks":0,"open_issues":7,"watchers":0,"default_branch":"master"}},"base":{"label":"nodejs:master","ref":"master","sha":"f34caa96d1c6374aa44999f41aa538d1171abd0c","user":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"repo":{"id":27193779,"name":"node","full_name":"nodejs/node","owner":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nodejs/node","description":"Node.js JavaScript runtime :sparkles::turtle::rocket::sparkles:","fork":false,"url":"https://api.github.com/repos/nodejs/node","forks_url":"https://api.github.com/repos/nodejs/node/forks","keys_url":"https://api.github.com/repos/nodejs/node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nodejs/node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nodejs/node/teams","hooks_url":"https://api.github.com/repos/nodejs/node/hooks","issue_events_url":"https://api.github.com/repos/nodejs/node/issues/events{/number}","events_url":"https://api.github.com/repos/nodejs/node/events","assignees_url":"https://api.github.com/repos/nodejs/node/assignees{/user}","branches_url":"https://api.github.com/repos/nodejs/node/branches{/branch}","tags_url":"https://api.github.com/repos/nodejs/node/tags","blobs_url":"https://api.github.com/repos/nodejs/node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nodejs/node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nodejs/node/git/refs{/sha}","trees_url":"https://api.github.com/repos/nodejs/node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nodejs/node/statuses/{sha}","languages_url":"https://api.github.com/repos/nodejs/node/languages","stargazers_url":"https://api.github.com/repos/nodejs/node/stargazers","contributors_url":"https://api.github.com/repos/nodejs/node/contributors","subscribers_url":"https://api.github.com/repos/nodejs/node/subscribers","subscription_url":"https://api.github.com/repos/nodejs/node/subscription","commits_url":"https://api.github.com/repos/nodejs/node/commits{/sha}","git_commits_url":"https://api.github.com/repos/nodejs/node/git/commits{/sha}","comments_url":"https://api.github.com/repos/nodejs/node/comments{/number}","issue_comment_url":"https://api.github.com/repos/nodejs/node/issues/comments{/number}","contents_url":"https://api.github.com/repos/nodejs/node/contents/{+path}","compare_url":"https://api.github.com/repos/nodejs/node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nodejs/node/merges","archive_url":"https://api.github.com/repos/nodejs/node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nodejs/node/downloads","issues_url":"https://api.github.com/repos/nodejs/node/issues{/number}","pulls_url":"https://api.github.com/repos/nodejs/node/pulls{/number}","milestones_url":"https://api.github.com/repos/nodejs/node/milestones{/number}","notifications_url":"https://api.github.com/repos/nodejs/node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nodejs/node/labels{/name}","releases_url":"https://api.github.com/repos/nodejs/node/releases{/id}","deployments_url":"https://api.github.com/repos/nodejs/node/deployments","created_at":"2014-11-26T19:57:11Z","updated_at":"2016-06-23T08:10:17Z","pushed_at":"2016-06-23T07:31:03Z","git_url":"git://github.com/nodejs/node.git","ssh_url":"git@github.com:nodejs/node.git","clone_url":"https://github.com/nodejs/node.git","svn_url":"https://github.com/nodejs/node","homepage":"https://nodejs.org","size":283445,"stargazers_count":24260,"watchers_count":24260,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3572,"mirror_url":null,"open_issues_count":708,"forks":3572,"open_issues":708,"watchers":24260,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nodejs/node/pulls/7271"},"html":{"href":"https://github.com/nodejs/node/pull/7271"},"issue":{"href":"https://api.github.com/repos/nodejs/node/issues/7271"},"comments":{"href":"https://api.github.com/repos/nodejs/node/issues/7271/comments"},"review_comments":{"href":"https://api.github.com/repos/nodejs/node/pulls/7271/comments"},"review_comment":{"href":"https://api.github.com/repos/nodejs/node/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nodejs/node/pulls/7271/commits"},"statuses":{"href":"https://api.github.com/repos/nodejs/node/statuses/4ec2db931909040a6c5353acb1581647837c9e7d"}}}}
{"actor":{"display_login":"bnoordhuis"}}