{"action":"created","comment":{"url":"https://api.github.com/repos/streadway/amqp/pulls/comments/89517936","pull_request_review_id":10063382,"id":89517936,"diff_hunk":"@@ -141,7 +141,11 @@ func (me *Channel) open() error {\n // Performs a request/response call for when the message is not NoWait and is\n // specified as Synchronous.\n func (me *Channel) call(req message, res ...message) error {\n-\tif err := me.send(me, req); err != nil {\n+\tme.m.Lock()","path":"channel.go","position":5,"original_position":5,"commit_id":"0563adcdb2a14308873fce26b14d3637dc2ac685","original_commit_id":"0563adcdb2a14308873fce26b14d3637dc2ac685","user":{"login":"imkira","id":470338,"avatar_url":"https://avatars.githubusercontent.com/u/470338?v=3","gravatar_id":"","url":"https://api.github.com/users/imkira","html_url":"https://github.com/imkira","followers_url":"https://api.github.com/users/imkira/followers","following_url":"https://api.github.com/users/imkira/following{/other_user}","gists_url":"https://api.github.com/users/imkira/gists{/gist_id}","starred_url":"https://api.github.com/users/imkira/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imkira/subscriptions","organizations_url":"https://api.github.com/users/imkira/orgs","repos_url":"https://api.github.com/users/imkira/repos","events_url":"https://api.github.com/users/imkira/events{/privacy}","received_events_url":"https://api.github.com/users/imkira/received_events","type":"User","site_admin":false},"body":"The original code is very misleading.\r\nPlease note that m.send starts as `sendOpen` and then switches to `sendClosed`: \r\n\r\nhttps://github.com/imkira/amqp/blob/0563adcdb2a14308873fce26b14d3637dc2ac685/channel.go#L85\r\nhttps://github.com/imkira/amqp/blob/0563adcdb2a14308873fce26b14d3637dc2ac685/channel.go#L104\r\n\r\nPlease, also note that each of those 2 functions uses the mutex you specified for actually sending data.\r\n\r\nWhat I am doing here is to protecting a race condition that could happen if we used me.send directly.\r\nThat would collide with the following modification:\r\n\r\nhttps://github.com/imkira/amqp/blob/0563adcdb2a14308873fce26b14d3637dc2ac685/channel.go#L104\r\n\r\n","created_at":"2016-11-24T15:36:59Z","updated_at":"2016-11-24T15:36:59Z","html_url":"https://github.com/streadway/amqp/pull/196#discussion_r89517936","pull_request_url":"https://api.github.com/repos/streadway/amqp/pulls/196","_links":{"self":{"href":"https://api.github.com/repos/streadway/amqp/pulls/comments/89517936"},"html":{"href":"https://github.com/streadway/amqp/pull/196#discussion_r89517936"},"pull_request":{"href":"https://api.github.com/repos/streadway/amqp/pulls/196"}}},"pull_request":{"url":"https://api.github.com/repos/streadway/amqp/pulls/196","id":64290941,"html_url":"https://github.com/streadway/amqp/pull/196","diff_url":"https://github.com/streadway/amqp/pull/196.diff","patch_url":"https://github.com/streadway/amqp/pull/196.patch","issue_url":"https://api.github.com/repos/streadway/amqp/issues/196","number":196,"state":"open","locked":false,"title":"connection shutdown, channel close data race","user":{"login":"imkira","id":470338,"avatar_url":"https://avatars.githubusercontent.com/u/470338?v=3","gravatar_id":"","url":"https://api.github.com/users/imkira","html_url":"https://github.com/imkira","followers_url":"https://api.github.com/users/imkira/followers","following_url":"https://api.github.com/users/imkira/following{/other_user}","gists_url":"https://api.github.com/users/imkira/gists{/gist_id}","starred_url":"https://api.github.com/users/imkira/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imkira/subscriptions","organizations_url":"https://api.github.com/users/imkira/orgs","repos_url":"https://api.github.com/users/imkira/repos","events_url":"https://api.github.com/users/imkira/events{/privacy}","received_events_url":"https://api.github.com/users/imkira/received_events","type":"User","site_admin":false},"body":"I am running tests with `go test -v -race -cpu=1,2,4` and, I am not sure but, I think I found the following data race (commit `b4f3ceab0337f013208d31348b578d83c0064744`):\n\n```\n==================\nWARNING: DATA RACE\nRead by goroutine 79:\n  github.com/streadway/amqp.(*Channel).call()\n      /opt/go/src/github.com/streadway/amqp/channel.go:144 +0x70\n  github.com/streadway/amqp.(*Channel).Close()\n      /opt/go/src/github.com/streadway/amqp/channel.go:406 +0x207\n[ommited]\n\nPrevious write by goroutine 80:\n  github.com/streadway/amqp.(*Channel).shutdown.func1()\n      /opt/go/src/github.com/streadway/amqp/channel.go:104 +0x17b\n  sync.(*Once).Do()\n      /home/ubuntu/go/src/sync/once.go:44 +0xf6\n  github.com/streadway/amqp.(*Channel).shutdown()\n      /opt/go/src/github.com/streadway/amqp/channel.go:134 +0x98\n  github.com/streadway/amqp.(*Connection).closeChannel()\n      /opt/go/src/github.com/streadway/amqp/connection.go:580 +0x38\n  github.com/streadway/amqp.(*Connection).shutdown.func1()\n      /opt/go/src/github.com/streadway/amqp/connection.go:350 +0x1d5\n  sync.(*Once).Do()\n      /home/ubuntu/go/src/sync/once.go:44 +0xf6\n  github.com/streadway/amqp.(*Connection).shutdown()\n      /opt/go/src/github.com/streadway/amqp/connection.go:370 +0x93\n  github.com/streadway/amqp.(*Connection).dispatch0()\n      /opt/go/src/github.com/streadway/amqp/connection.go:394 +0x4d5\n  github.com/streadway/amqp.(*Connection).demux()\n      /opt/go/src/github.com/streadway/amqp/connection.go:377 +0x62\n  github.com/streadway/amqp.(*Connection).reader()\n      /opt/go/src/github.com/streadway/amqp/connection.go:471 +0x322\n```\n\nIt appears that `Connection.shutdown` is accessing `me.channels` to close them (goroutine 80) without any kind of mutex locking, while concurrently getting a `Connection.releaseChannel` (via `channel.Close`) which accesses `me.channels` too (using the connection lock though).\n\nAfter trying to fix this by protecting `Connection.shutdown` I noticed I started having another race condition due to `Channel.call` accessing `me.send` while `Channel.shutdown` changes it to `sendClosed`.\n\nSeriously, I don't know if this the correct fix.\nI wrote a simple test that causes at least one of these issues to happen, and enabled `-race` for travis builds.\nThere is another data race related to IO handling in `shared_test.go` or whatever.\nI didn't understand exactly what the problem was, but it looked like a test code-only problem, and since it is out of the scope of this PR I leave it open for you to take a look first.\n","created_at":"2016-03-28T05:35:50Z","updated_at":"2016-11-24T15:36:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d3896f3c83f5e649139195cb587c4253ab123044","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/streadway/amqp/pulls/196/commits","review_comments_url":"https://api.github.com/repos/streadway/amqp/pulls/196/comments","review_comment_url":"https://api.github.com/repos/streadway/amqp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/streadway/amqp/issues/196/comments","statuses_url":"https://api.github.com/repos/streadway/amqp/statuses/0563adcdb2a14308873fce26b14d3637dc2ac685","head":{"label":"imkira:hotfix/connection-shutdown-race","ref":"hotfix/connection-shutdown-race","sha":"0563adcdb2a14308873fce26b14d3637dc2ac685","user":{"login":"imkira","id":470338,"avatar_url":"https://avatars.githubusercontent.com/u/470338?v=3","gravatar_id":"","url":"https://api.github.com/users/imkira","html_url":"https://github.com/imkira","followers_url":"https://api.github.com/users/imkira/followers","following_url":"https://api.github.com/users/imkira/following{/other_user}","gists_url":"https://api.github.com/users/imkira/gists{/gist_id}","starred_url":"https://api.github.com/users/imkira/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imkira/subscriptions","organizations_url":"https://api.github.com/users/imkira/orgs","repos_url":"https://api.github.com/users/imkira/repos","events_url":"https://api.github.com/users/imkira/events{/privacy}","received_events_url":"https://api.github.com/users/imkira/received_events","type":"User","site_admin":false},"repo":{"id":54858394,"name":"amqp","full_name":"imkira/amqp","owner":{"login":"imkira","id":470338,"avatar_url":"https://avatars.githubusercontent.com/u/470338?v=3","gravatar_id":"","url":"https://api.github.com/users/imkira","html_url":"https://github.com/imkira","followers_url":"https://api.github.com/users/imkira/followers","following_url":"https://api.github.com/users/imkira/following{/other_user}","gists_url":"https://api.github.com/users/imkira/gists{/gist_id}","starred_url":"https://api.github.com/users/imkira/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imkira/subscriptions","organizations_url":"https://api.github.com/users/imkira/orgs","repos_url":"https://api.github.com/users/imkira/repos","events_url":"https://api.github.com/users/imkira/events{/privacy}","received_events_url":"https://api.github.com/users/imkira/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/imkira/amqp","description":"Go client for AMQP 0.9.1","fork":true,"url":"https://api.github.com/repos/imkira/amqp","forks_url":"https://api.github.com/repos/imkira/amqp/forks","keys_url":"https://api.github.com/repos/imkira/amqp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/imkira/amqp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/imkira/amqp/teams","hooks_url":"https://api.github.com/repos/imkira/amqp/hooks","issue_events_url":"https://api.github.com/repos/imkira/amqp/issues/events{/number}","events_url":"https://api.github.com/repos/imkira/amqp/events","assignees_url":"https://api.github.com/repos/imkira/amqp/assignees{/user}","branches_url":"https://api.github.com/repos/imkira/amqp/branches{/branch}","tags_url":"https://api.github.com/repos/imkira/amqp/tags","blobs_url":"https://api.github.com/repos/imkira/amqp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/imkira/amqp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/imkira/amqp/git/refs{/sha}","trees_url":"https://api.github.com/repos/imkira/amqp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/imkira/amqp/statuses/{sha}","languages_url":"https://api.github.com/repos/imkira/amqp/languages","stargazers_url":"https://api.github.com/repos/imkira/amqp/stargazers","contributors_url":"https://api.github.com/repos/imkira/amqp/contributors","subscribers_url":"https://api.github.com/repos/imkira/amqp/subscribers","subscription_url":"https://api.github.com/repos/imkira/amqp/subscription","commits_url":"https://api.github.com/repos/imkira/amqp/commits{/sha}","git_commits_url":"https://api.github.com/repos/imkira/amqp/git/commits{/sha}","comments_url":"https://api.github.com/repos/imkira/amqp/comments{/number}","issue_comment_url":"https://api.github.com/repos/imkira/amqp/issues/comments{/number}","contents_url":"https://api.github.com/repos/imkira/amqp/contents/{+path}","compare_url":"https://api.github.com/repos/imkira/amqp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/imkira/amqp/merges","archive_url":"https://api.github.com/repos/imkira/amqp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/imkira/amqp/downloads","issues_url":"https://api.github.com/repos/imkira/amqp/issues{/number}","pulls_url":"https://api.github.com/repos/imkira/amqp/pulls{/number}","milestones_url":"https://api.github.com/repos/imkira/amqp/milestones{/number}","notifications_url":"https://api.github.com/repos/imkira/amqp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/imkira/amqp/labels{/name}","releases_url":"https://api.github.com/repos/imkira/amqp/releases{/id}","deployments_url":"https://api.github.com/repos/imkira/amqp/deployments","created_at":"2016-03-28T02:04:54Z","updated_at":"2016-03-28T02:04:54Z","pushed_at":"2016-03-29T07:08:07Z","git_url":"git://github.com/imkira/amqp.git","ssh_url":"git@github.com:imkira/amqp.git","clone_url":"https://github.com/imkira/amqp.git","svn_url":"https://github.com/imkira/amqp","homepage":"http://godoc.org/github.com/streadway/amqp","size":675,"stargazers_count":0,"watchers_count":0,"language":"Go","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":"streadway:master","ref":"master","sha":"2e25825abdbd7752ff08b270d313b93519a0a232","user":{"login":"streadway","id":19727,"avatar_url":"https://avatars.githubusercontent.com/u/19727?v=3","gravatar_id":"","url":"https://api.github.com/users/streadway","html_url":"https://github.com/streadway","followers_url":"https://api.github.com/users/streadway/followers","following_url":"https://api.github.com/users/streadway/following{/other_user}","gists_url":"https://api.github.com/users/streadway/gists{/gist_id}","starred_url":"https://api.github.com/users/streadway/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/streadway/subscriptions","organizations_url":"https://api.github.com/users/streadway/orgs","repos_url":"https://api.github.com/users/streadway/repos","events_url":"https://api.github.com/users/streadway/events{/privacy}","received_events_url":"https://api.github.com/users/streadway/received_events","type":"User","site_admin":false},"repo":{"id":4141925,"name":"amqp","full_name":"streadway/amqp","owner":{"login":"streadway","id":19727,"avatar_url":"https://avatars.githubusercontent.com/u/19727?v=3","gravatar_id":"","url":"https://api.github.com/users/streadway","html_url":"https://github.com/streadway","followers_url":"https://api.github.com/users/streadway/followers","following_url":"https://api.github.com/users/streadway/following{/other_user}","gists_url":"https://api.github.com/users/streadway/gists{/gist_id}","starred_url":"https://api.github.com/users/streadway/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/streadway/subscriptions","organizations_url":"https://api.github.com/users/streadway/orgs","repos_url":"https://api.github.com/users/streadway/repos","events_url":"https://api.github.com/users/streadway/events{/privacy}","received_events_url":"https://api.github.com/users/streadway/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/streadway/amqp","description":"Go client for AMQP 0.9.1","fork":false,"url":"https://api.github.com/repos/streadway/amqp","forks_url":"https://api.github.com/repos/streadway/amqp/forks","keys_url":"https://api.github.com/repos/streadway/amqp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/streadway/amqp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/streadway/amqp/teams","hooks_url":"https://api.github.com/repos/streadway/amqp/hooks","issue_events_url":"https://api.github.com/repos/streadway/amqp/issues/events{/number}","events_url":"https://api.github.com/repos/streadway/amqp/events","assignees_url":"https://api.github.com/repos/streadway/amqp/assignees{/user}","branches_url":"https://api.github.com/repos/streadway/amqp/branches{/branch}","tags_url":"https://api.github.com/repos/streadway/amqp/tags","blobs_url":"https://api.github.com/repos/streadway/amqp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/streadway/amqp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/streadway/amqp/git/refs{/sha}","trees_url":"https://api.github.com/repos/streadway/amqp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/streadway/amqp/statuses/{sha}","languages_url":"https://api.github.com/repos/streadway/amqp/languages","stargazers_url":"https://api.github.com/repos/streadway/amqp/stargazers","contributors_url":"https://api.github.com/repos/streadway/amqp/contributors","subscribers_url":"https://api.github.com/repos/streadway/amqp/subscribers","subscription_url":"https://api.github.com/repos/streadway/amqp/subscription","commits_url":"https://api.github.com/repos/streadway/amqp/commits{/sha}","git_commits_url":"https://api.github.com/repos/streadway/amqp/git/commits{/sha}","comments_url":"https://api.github.com/repos/streadway/amqp/comments{/number}","issue_comment_url":"https://api.github.com/repos/streadway/amqp/issues/comments{/number}","contents_url":"https://api.github.com/repos/streadway/amqp/contents/{+path}","compare_url":"https://api.github.com/repos/streadway/amqp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/streadway/amqp/merges","archive_url":"https://api.github.com/repos/streadway/amqp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/streadway/amqp/downloads","issues_url":"https://api.github.com/repos/streadway/amqp/issues{/number}","pulls_url":"https://api.github.com/repos/streadway/amqp/pulls{/number}","milestones_url":"https://api.github.com/repos/streadway/amqp/milestones{/number}","notifications_url":"https://api.github.com/repos/streadway/amqp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/streadway/amqp/labels{/name}","releases_url":"https://api.github.com/repos/streadway/amqp/releases{/id}","deployments_url":"https://api.github.com/repos/streadway/amqp/deployments","created_at":"2012-04-25T22:11:52Z","updated_at":"2016-11-24T12:32:27Z","pushed_at":"2016-11-24T15:03:53Z","git_url":"git://github.com/streadway/amqp.git","ssh_url":"git@github.com:streadway/amqp.git","clone_url":"https://github.com/streadway/amqp.git","svn_url":"https://github.com/streadway/amqp","homepage":"http://godoc.org/github.com/streadway/amqp","size":1699,"stargazers_count":1031,"watchers_count":1031,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":199,"mirror_url":null,"open_issues_count":53,"forks":199,"open_issues":53,"watchers":1031,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/streadway/amqp/pulls/196"},"html":{"href":"https://github.com/streadway/amqp/pull/196"},"issue":{"href":"https://api.github.com/repos/streadway/amqp/issues/196"},"comments":{"href":"https://api.github.com/repos/streadway/amqp/issues/196/comments"},"review_comments":{"href":"https://api.github.com/repos/streadway/amqp/pulls/196/comments"},"review_comment":{"href":"https://api.github.com/repos/streadway/amqp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/streadway/amqp/pulls/196/commits"},"statuses":{"href":"https://api.github.com/repos/streadway/amqp/statuses/0563adcdb2a14308873fce26b14d3637dc2ac685"}}}}
{"actor":{"display_login":"imkira"}}