{"action":"created","comment":{"url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/pulls/comments/69536021","id":69536021,"diff_hunk":"@@ -250,6 +250,88 @@\n       end\n     end\n \n+    context 'when the response_to does not match the request_id' do\n+\n+      let(:documents) do\n+        [{ 'name' => 'bob' }, { 'name' => 'alice' }]\n+      end\n+\n+      let(:insert) do\n+        Mongo::Protocol::Insert.new(TEST_DB, TEST_COLL, documents)\n+      end\n+\n+      let(:query_bob) do\n+        Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { 'name' => 'bob' })\n+      end\n+\n+      let(:query_alice) do\n+        Mongo::Protocol::Query.new(TEST_DB, TEST_COLL, { 'name' => 'alice' })\n+      end\n+\n+      after do\n+        authorized_collection.delete_many\n+      end\n+\n+      before do\n+        # Fake a query for which we did not read the response. See RUBY-1117\n+        allow(query_bob).to receive(:replyable?) { false }\n+        connection.dispatch([ insert, query_bob ])\n+      end\n+\n+      it 'raises an UnexpectedResponse' do\n+        expect {\n+          connection.dispatch([ query_alice ])\n+        }.to raise_error(Mongo::Error::UnexpectedResponse, /Unexpected response. Got response for request ID \\d+ but expected response for request ID \\d+/)","path":"spec/mongo/server/connection_spec.rb","position":35,"original_position":35,"commit_id":"7e2e94d9967c72409ff53da4d04860b3a1493992","original_commit_id":"7e2e94d9967c72409ff53da4d04860b3a1493992","user":{"login":"jarthod","id":201687,"avatar_url":"https://avatars.githubusercontent.com/u/201687?v=3","gravatar_id":"","url":"https://api.github.com/users/jarthod","html_url":"https://github.com/jarthod","followers_url":"https://api.github.com/users/jarthod/followers","following_url":"https://api.github.com/users/jarthod/following{/other_user}","gists_url":"https://api.github.com/users/jarthod/gists{/gist_id}","starred_url":"https://api.github.com/users/jarthod/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jarthod/subscriptions","organizations_url":"https://api.github.com/users/jarthod/orgs","repos_url":"https://api.github.com/users/jarthod/repos","events_url":"https://api.github.com/users/jarthod/events{/privacy}","received_events_url":"https://api.github.com/users/jarthod/received_events","type":"User","site_admin":false},"body":"sure","created_at":"2016-07-05T09:53:48Z","updated_at":"2016-07-05T09:53:48Z","html_url":"https://github.com/mongodb/mongo-ruby-driver/pull/774#discussion_r69536021","pull_request_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/pulls/774","_links":{"self":{"href":"https://api.github.com/repos/mongodb/mongo-ruby-driver/pulls/comments/69536021"},"html":{"href":"https://github.com/mongodb/mongo-ruby-driver/pull/774#discussion_r69536021"},"pull_request":{"href":"https://api.github.com/repos/mongodb/mongo-ruby-driver/pulls/774"}}},"pull_request":{"url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/pulls/774","id":75309192,"html_url":"https://github.com/mongodb/mongo-ruby-driver/pull/774","diff_url":"https://github.com/mongodb/mongo-ruby-driver/pull/774.diff","patch_url":"https://github.com/mongodb/mongo-ruby-driver/pull/774.patch","issue_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/issues/774","number":774,"state":"open","locked":false,"title":"RUBY-1117 Ensure the driver returns the response to the current query","user":{"login":"elhu","id":578161,"avatar_url":"https://avatars.githubusercontent.com/u/578161?v=3","gravatar_id":"","url":"https://api.github.com/users/elhu","html_url":"https://github.com/elhu","followers_url":"https://api.github.com/users/elhu/followers","following_url":"https://api.github.com/users/elhu/following{/other_user}","gists_url":"https://api.github.com/users/elhu/gists{/gist_id}","starred_url":"https://api.github.com/users/elhu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elhu/subscriptions","organizations_url":"https://api.github.com/users/elhu/orgs","repos_url":"https://api.github.com/users/elhu/repos","events_url":"https://api.github.com/users/elhu/events{/privacy}","received_events_url":"https://api.github.com/users/elhu/received_events","type":"User","site_admin":false},"body":"Hello!\r\n\r\nAs discussed in https://jira.mongodb.org/browse/RUBY-1117, we discovered an issue in the Mongo ruby driver: if a thread dies before it has time to read the response to a query it triggered, then the next thread to read from that socket will return an incorrect response.\r\n\r\nWe've addressed the issue by ensuring that we were returning the proper response in `Mongo::Server::Connection#deliver`. If `response_to` does not match the `request_id` of the current query, the next response is read.\r\n\r\nIn fixing this bug, we also discovered that the class instance variables set in `Mongo::Protocol::Message.deserialize_header` were not thread-safe. In order to avoid this problem, we decided to replace them by local variables, since they did not seem to be used anywhere.\r\n\r\nWe've tried to provide meaningful specs as well, please let us know if there are things you wish to discuss before this can be merged!\r\n\r\nMany thanks to @jarthod for helping me figure out this one.","created_at":"2016-06-27T13:16:54Z","updated_at":"2016-07-05T09:53:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"966223b97733bfb48e85bd608e9ea25249528e99","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/pulls/774/commits","review_comments_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/pulls/774/comments","review_comment_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/issues/774/comments","statuses_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/statuses/7e2e94d9967c72409ff53da4d04860b3a1493992","head":{"label":"dimelo:master","ref":"master","sha":"7e2e94d9967c72409ff53da4d04860b3a1493992","user":{"login":"dimelo","id":313756,"avatar_url":"https://avatars.githubusercontent.com/u/313756?v=3","gravatar_id":"","url":"https://api.github.com/users/dimelo","html_url":"https://github.com/dimelo","followers_url":"https://api.github.com/users/dimelo/followers","following_url":"https://api.github.com/users/dimelo/following{/other_user}","gists_url":"https://api.github.com/users/dimelo/gists{/gist_id}","starred_url":"https://api.github.com/users/dimelo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimelo/subscriptions","organizations_url":"https://api.github.com/users/dimelo/orgs","repos_url":"https://api.github.com/users/dimelo/repos","events_url":"https://api.github.com/users/dimelo/events{/privacy}","received_events_url":"https://api.github.com/users/dimelo/received_events","type":"Organization","site_admin":false},"repo":{"id":61898111,"name":"mongo-ruby-driver","full_name":"dimelo/mongo-ruby-driver","owner":{"login":"dimelo","id":313756,"avatar_url":"https://avatars.githubusercontent.com/u/313756?v=3","gravatar_id":"","url":"https://api.github.com/users/dimelo","html_url":"https://github.com/dimelo","followers_url":"https://api.github.com/users/dimelo/followers","following_url":"https://api.github.com/users/dimelo/following{/other_user}","gists_url":"https://api.github.com/users/dimelo/gists{/gist_id}","starred_url":"https://api.github.com/users/dimelo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimelo/subscriptions","organizations_url":"https://api.github.com/users/dimelo/orgs","repos_url":"https://api.github.com/users/dimelo/repos","events_url":"https://api.github.com/users/dimelo/events{/privacy}","received_events_url":"https://api.github.com/users/dimelo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimelo/mongo-ruby-driver","description":"Ruby driver for MongoDB","fork":true,"url":"https://api.github.com/repos/dimelo/mongo-ruby-driver","forks_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/forks","keys_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/teams","hooks_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/hooks","issue_events_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/issues/events{/number}","events_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/events","assignees_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/assignees{/user}","branches_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/branches{/branch}","tags_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/tags","blobs_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/statuses/{sha}","languages_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/languages","stargazers_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/stargazers","contributors_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/contributors","subscribers_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/subscribers","subscription_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/subscription","commits_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/contents/{+path}","compare_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/merges","archive_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/downloads","issues_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/issues{/number}","pulls_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/pulls{/number}","milestones_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/milestones{/number}","notifications_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/labels{/name}","releases_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/releases{/id}","deployments_url":"https://api.github.com/repos/dimelo/mongo-ruby-driver/deployments","created_at":"2016-06-24T16:36:07Z","updated_at":"2016-06-24T16:36:09Z","pushed_at":"2016-06-30T15:15:33Z","git_url":"git://github.com/dimelo/mongo-ruby-driver.git","ssh_url":"git@github.com:dimelo/mongo-ruby-driver.git","clone_url":"https://github.com/dimelo/mongo-ruby-driver.git","svn_url":"https://github.com/dimelo/mongo-ruby-driver","homepage":"http://api.mongodb.org/ruby","size":31909,"stargazers_count":0,"watchers_count":0,"language":"Ruby","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":"mongodb:master","ref":"master","sha":"21ba665f2c80934e2073bedc42f86d933bccb8f4","user":{"login":"mongodb","id":45120,"avatar_url":"https://avatars.githubusercontent.com/u/45120?v=3","gravatar_id":"","url":"https://api.github.com/users/mongodb","html_url":"https://github.com/mongodb","followers_url":"https://api.github.com/users/mongodb/followers","following_url":"https://api.github.com/users/mongodb/following{/other_user}","gists_url":"https://api.github.com/users/mongodb/gists{/gist_id}","starred_url":"https://api.github.com/users/mongodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mongodb/subscriptions","organizations_url":"https://api.github.com/users/mongodb/orgs","repos_url":"https://api.github.com/users/mongodb/repos","events_url":"https://api.github.com/users/mongodb/events{/privacy}","received_events_url":"https://api.github.com/users/mongodb/received_events","type":"Organization","site_admin":false},"repo":{"id":108125,"name":"mongo-ruby-driver","full_name":"mongodb/mongo-ruby-driver","owner":{"login":"mongodb","id":45120,"avatar_url":"https://avatars.githubusercontent.com/u/45120?v=3","gravatar_id":"","url":"https://api.github.com/users/mongodb","html_url":"https://github.com/mongodb","followers_url":"https://api.github.com/users/mongodb/followers","following_url":"https://api.github.com/users/mongodb/following{/other_user}","gists_url":"https://api.github.com/users/mongodb/gists{/gist_id}","starred_url":"https://api.github.com/users/mongodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mongodb/subscriptions","organizations_url":"https://api.github.com/users/mongodb/orgs","repos_url":"https://api.github.com/users/mongodb/repos","events_url":"https://api.github.com/users/mongodb/events{/privacy}","received_events_url":"https://api.github.com/users/mongodb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mongodb/mongo-ruby-driver","description":"Ruby driver for MongoDB","fork":false,"url":"https://api.github.com/repos/mongodb/mongo-ruby-driver","forks_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/forks","keys_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/teams","hooks_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/hooks","issue_events_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/issues/events{/number}","events_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/events","assignees_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/assignees{/user}","branches_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/branches{/branch}","tags_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/tags","blobs_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/git/refs{/sha}","trees_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/statuses/{sha}","languages_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/languages","stargazers_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/stargazers","contributors_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/contributors","subscribers_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/subscribers","subscription_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/subscription","commits_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/commits{/sha}","git_commits_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/git/commits{/sha}","comments_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/comments{/number}","issue_comment_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/issues/comments{/number}","contents_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/contents/{+path}","compare_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/merges","archive_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/downloads","issues_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/issues{/number}","pulls_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/pulls{/number}","milestones_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/milestones{/number}","notifications_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/labels{/name}","releases_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/releases{/id}","deployments_url":"https://api.github.com/repos/mongodb/mongo-ruby-driver/deployments","created_at":"2009-01-15T16:40:45Z","updated_at":"2016-07-03T19:21:36Z","pushed_at":"2016-07-04T15:40:16Z","git_url":"git://github.com/mongodb/mongo-ruby-driver.git","ssh_url":"git@github.com:mongodb/mongo-ruby-driver.git","clone_url":"https://github.com/mongodb/mongo-ruby-driver.git","svn_url":"https://github.com/mongodb/mongo-ruby-driver","homepage":"http://api.mongodb.org/ruby","size":34064,"stargazers_count":1262,"watchers_count":1262,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":415,"mirror_url":null,"open_issues_count":13,"forks":415,"open_issues":13,"watchers":1262,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mongodb/mongo-ruby-driver/pulls/774"},"html":{"href":"https://github.com/mongodb/mongo-ruby-driver/pull/774"},"issue":{"href":"https://api.github.com/repos/mongodb/mongo-ruby-driver/issues/774"},"comments":{"href":"https://api.github.com/repos/mongodb/mongo-ruby-driver/issues/774/comments"},"review_comments":{"href":"https://api.github.com/repos/mongodb/mongo-ruby-driver/pulls/774/comments"},"review_comment":{"href":"https://api.github.com/repos/mongodb/mongo-ruby-driver/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mongodb/mongo-ruby-driver/pulls/774/commits"},"statuses":{"href":"https://api.github.com/repos/mongodb/mongo-ruby-driver/statuses/7e2e94d9967c72409ff53da4d04860b3a1493992"}}}}
{"actor":{"display_login":"jarthod"}}