{"action":"created","comment":{"url":"https://api.github.com/repos/prestodb/presto/pulls/comments/209108119","pull_request_review_id":145061171,"id":209108119,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwOTEwODExOQ==","diff_hunk":"@@ -116,6 +117,25 @@ public void testNormalFinish()\n         assertTrue(source.isFinished());\n     }\n \n+    @Test(invocationCount = 10_000, timeOut = 5_000)\n+    public void testConcurrentClose()\n+    {\n+        List<Type> types = ImmutableList.of(VARCHAR, BIGINT, BIGINT);\n+        OperatorContext operatorContext = driverContext.addOperatorContext(0, new PlanNodeId(\"test\"), \"values\");\n+        ValuesOperator source = new ValuesOperator(operatorContext, rowPagesBuilder(types)\n+                .addSequencePage(10, 20, 30, 40)\n+                .build());\n+\n+        Operator sink = createSinkOperator(types);\n+        Driver driver = Driver.createDriver(driverContext, source, sink);\n+        // let these threads race\n+        scheduledExecutor.submit(() -> driver.processFor(new Duration(1, TimeUnit.NANOSECONDS))); // don't want to call isFinishedInternal in processFor\n+        scheduledExecutor.submit(() -> driver.close());\n+        while (!driverContext.isDone()) {\n+            Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS);","path":"presto-main/src/test/java/com/facebook/presto/operator/TestDriver.java","position":27,"original_position":27,"commit_id":"37bf0adaf78e88c0db0f5392cf6e118c98395056","original_commit_id":"37bf0adaf78e88c0db0f5392cf6e118c98395056","user":{"login":"dain","id":58298,"node_id":"MDQ6VXNlcjU4Mjk4","avatar_url":"https://avatars0.githubusercontent.com/u/58298?v=4","gravatar_id":"","url":"https://api.github.com/users/dain","html_url":"https://github.com/dain","followers_url":"https://api.github.com/users/dain/followers","following_url":"https://api.github.com/users/dain/following{/other_user}","gists_url":"https://api.github.com/users/dain/gists{/gist_id}","starred_url":"https://api.github.com/users/dain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dain/subscriptions","organizations_url":"https://api.github.com/users/dain/orgs","repos_url":"https://api.github.com/users/dain/repos","events_url":"https://api.github.com/users/dain/events{/privacy}","received_events_url":"https://api.github.com/users/dain/received_events","type":"User","site_admin":false},"body":"maybe try 1s","created_at":"2018-08-09T23:25:08Z","updated_at":"2018-08-09T23:25:14Z","html_url":"https://github.com/prestodb/presto/pull/11238#discussion_r209108119","pull_request_url":"https://api.github.com/repos/prestodb/presto/pulls/11238","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/prestodb/presto/pulls/comments/209108119"},"html":{"href":"https://github.com/prestodb/presto/pull/11238#discussion_r209108119"},"pull_request":{"href":"https://api.github.com/repos/prestodb/presto/pulls/11238"}}},"pull_request":{"url":"https://api.github.com/repos/prestodb/presto/pulls/11238","id":207464167,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA3NDY0MTY3","html_url":"https://github.com/prestodb/presto/pull/11238","diff_url":"https://github.com/prestodb/presto/pull/11238.diff","patch_url":"https://github.com/prestodb/presto/pull/11238.patch","issue_url":"https://api.github.com/repos/prestodb/presto/issues/11238","number":11238,"state":"open","locked":false,"title":"Fix the race between close and destroy in the Driver","user":{"login":"nezihyigitbasi","id":1223839,"node_id":"MDQ6VXNlcjEyMjM4Mzk=","avatar_url":"https://avatars3.githubusercontent.com/u/1223839?v=4","gravatar_id":"","url":"https://api.github.com/users/nezihyigitbasi","html_url":"https://github.com/nezihyigitbasi","followers_url":"https://api.github.com/users/nezihyigitbasi/followers","following_url":"https://api.github.com/users/nezihyigitbasi/following{/other_user}","gists_url":"https://api.github.com/users/nezihyigitbasi/gists{/gist_id}","starred_url":"https://api.github.com/users/nezihyigitbasi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nezihyigitbasi/subscriptions","organizations_url":"https://api.github.com/users/nezihyigitbasi/orgs","repos_url":"https://api.github.com/users/nezihyigitbasi/repos","events_url":"https://api.github.com/users/nezihyigitbasi/events{/privacy}","received_events_url":"https://api.github.com/users/nezihyigitbasi/received_events","type":"User","site_admin":false},"body":"There is a race condition where a driver thread may not destroy the\r\noperators even though it's closed. This is not desirable as there are\r\nparts of the code that rely on the operators to be destroyed by the\r\ndriver, e.g., memory tracking related code.\r\n\r\nThe race occurs when a driver thread T1 is in the tryWithLock method and\r\nholds the exclusiveLock, and it has already called the\r\ndestroyIfNecessary() method. At this point T1 hasn't destroyed the operators\r\nyet as the driver hasn't been closed. Now if the task owning those splits\r\ngets aborted (say due to a LIMIT query), another thread T2 will call\r\ndriver.close(), and in close() it will try to acquire the lock to destroy the\r\noperators, but T1 still holds that lock. Then, T1 releases the lock and checks\r\nthe condition `while (pendingTaskSourceUpdates.get() != null\r\n&& state.get() == State.ALIVE && exclusiveLock.tryLock())`, and this condition\r\nis false as the state is NEED_DESTRUCTION (as the driver is closed by T2). At this\r\npoint T1 just exits without destroying the operators.","created_at":"2018-08-09T22:45:52Z","updated_at":"2018-08-09T23:25:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5bb7a04eb453772decab05395010a46e0094e270","assignee":{"login":"dain","id":58298,"node_id":"MDQ6VXNlcjU4Mjk4","avatar_url":"https://avatars0.githubusercontent.com/u/58298?v=4","gravatar_id":"","url":"https://api.github.com/users/dain","html_url":"https://github.com/dain","followers_url":"https://api.github.com/users/dain/followers","following_url":"https://api.github.com/users/dain/following{/other_user}","gists_url":"https://api.github.com/users/dain/gists{/gist_id}","starred_url":"https://api.github.com/users/dain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dain/subscriptions","organizations_url":"https://api.github.com/users/dain/orgs","repos_url":"https://api.github.com/users/dain/repos","events_url":"https://api.github.com/users/dain/events{/privacy}","received_events_url":"https://api.github.com/users/dain/received_events","type":"User","site_admin":false},"assignees":[{"login":"dain","id":58298,"node_id":"MDQ6VXNlcjU4Mjk4","avatar_url":"https://avatars0.githubusercontent.com/u/58298?v=4","gravatar_id":"","url":"https://api.github.com/users/dain","html_url":"https://github.com/dain","followers_url":"https://api.github.com/users/dain/followers","following_url":"https://api.github.com/users/dain/following{/other_user}","gists_url":"https://api.github.com/users/dain/gists{/gist_id}","starred_url":"https://api.github.com/users/dain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dain/subscriptions","organizations_url":"https://api.github.com/users/dain/orgs","repos_url":"https://api.github.com/users/dain/repos","events_url":"https://api.github.com/users/dain/events{/privacy}","received_events_url":"https://api.github.com/users/dain/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":196992743,"node_id":"MDU6TGFiZWwxOTY5OTI3NDM=","url":"https://api.github.com/repos/prestodb/presto/labels/CLA%20Signed","name":"CLA Signed","color":"ededed","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/prestodb/presto/pulls/11238/commits","review_comments_url":"https://api.github.com/repos/prestodb/presto/pulls/11238/comments","review_comment_url":"https://api.github.com/repos/prestodb/presto/pulls/comments{/number}","comments_url":"https://api.github.com/repos/prestodb/presto/issues/11238/comments","statuses_url":"https://api.github.com/repos/prestodb/presto/statuses/37bf0adaf78e88c0db0f5392cf6e118c98395056","head":{"label":"nezihyigitbasi:fix-driver-race","ref":"fix-driver-race","sha":"37bf0adaf78e88c0db0f5392cf6e118c98395056","user":{"login":"nezihyigitbasi","id":1223839,"node_id":"MDQ6VXNlcjEyMjM4Mzk=","avatar_url":"https://avatars3.githubusercontent.com/u/1223839?v=4","gravatar_id":"","url":"https://api.github.com/users/nezihyigitbasi","html_url":"https://github.com/nezihyigitbasi","followers_url":"https://api.github.com/users/nezihyigitbasi/followers","following_url":"https://api.github.com/users/nezihyigitbasi/following{/other_user}","gists_url":"https://api.github.com/users/nezihyigitbasi/gists{/gist_id}","starred_url":"https://api.github.com/users/nezihyigitbasi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nezihyigitbasi/subscriptions","organizations_url":"https://api.github.com/users/nezihyigitbasi/orgs","repos_url":"https://api.github.com/users/nezihyigitbasi/repos","events_url":"https://api.github.com/users/nezihyigitbasi/events{/privacy}","received_events_url":"https://api.github.com/users/nezihyigitbasi/received_events","type":"User","site_admin":false},"repo":{"id":20698188,"node_id":"MDEwOlJlcG9zaXRvcnkyMDY5ODE4OA==","name":"presto","full_name":"nezihyigitbasi/presto","owner":{"login":"nezihyigitbasi","id":1223839,"node_id":"MDQ6VXNlcjEyMjM4Mzk=","avatar_url":"https://avatars3.githubusercontent.com/u/1223839?v=4","gravatar_id":"","url":"https://api.github.com/users/nezihyigitbasi","html_url":"https://github.com/nezihyigitbasi","followers_url":"https://api.github.com/users/nezihyigitbasi/followers","following_url":"https://api.github.com/users/nezihyigitbasi/following{/other_user}","gists_url":"https://api.github.com/users/nezihyigitbasi/gists{/gist_id}","starred_url":"https://api.github.com/users/nezihyigitbasi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nezihyigitbasi/subscriptions","organizations_url":"https://api.github.com/users/nezihyigitbasi/orgs","repos_url":"https://api.github.com/users/nezihyigitbasi/repos","events_url":"https://api.github.com/users/nezihyigitbasi/events{/privacy}","received_events_url":"https://api.github.com/users/nezihyigitbasi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nezihyigitbasi/presto","description":"Distributed SQL query engine for big data","fork":true,"url":"https://api.github.com/repos/nezihyigitbasi/presto","forks_url":"https://api.github.com/repos/nezihyigitbasi/presto/forks","keys_url":"https://api.github.com/repos/nezihyigitbasi/presto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nezihyigitbasi/presto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nezihyigitbasi/presto/teams","hooks_url":"https://api.github.com/repos/nezihyigitbasi/presto/hooks","issue_events_url":"https://api.github.com/repos/nezihyigitbasi/presto/issues/events{/number}","events_url":"https://api.github.com/repos/nezihyigitbasi/presto/events","assignees_url":"https://api.github.com/repos/nezihyigitbasi/presto/assignees{/user}","branches_url":"https://api.github.com/repos/nezihyigitbasi/presto/branches{/branch}","tags_url":"https://api.github.com/repos/nezihyigitbasi/presto/tags","blobs_url":"https://api.github.com/repos/nezihyigitbasi/presto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nezihyigitbasi/presto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nezihyigitbasi/presto/git/refs{/sha}","trees_url":"https://api.github.com/repos/nezihyigitbasi/presto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nezihyigitbasi/presto/statuses/{sha}","languages_url":"https://api.github.com/repos/nezihyigitbasi/presto/languages","stargazers_url":"https://api.github.com/repos/nezihyigitbasi/presto/stargazers","contributors_url":"https://api.github.com/repos/nezihyigitbasi/presto/contributors","subscribers_url":"https://api.github.com/repos/nezihyigitbasi/presto/subscribers","subscription_url":"https://api.github.com/repos/nezihyigitbasi/presto/subscription","commits_url":"https://api.github.com/repos/nezihyigitbasi/presto/commits{/sha}","git_commits_url":"https://api.github.com/repos/nezihyigitbasi/presto/git/commits{/sha}","comments_url":"https://api.github.com/repos/nezihyigitbasi/presto/comments{/number}","issue_comment_url":"https://api.github.com/repos/nezihyigitbasi/presto/issues/comments{/number}","contents_url":"https://api.github.com/repos/nezihyigitbasi/presto/contents/{+path}","compare_url":"https://api.github.com/repos/nezihyigitbasi/presto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nezihyigitbasi/presto/merges","archive_url":"https://api.github.com/repos/nezihyigitbasi/presto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nezihyigitbasi/presto/downloads","issues_url":"https://api.github.com/repos/nezihyigitbasi/presto/issues{/number}","pulls_url":"https://api.github.com/repos/nezihyigitbasi/presto/pulls{/number}","milestones_url":"https://api.github.com/repos/nezihyigitbasi/presto/milestones{/number}","notifications_url":"https://api.github.com/repos/nezihyigitbasi/presto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nezihyigitbasi/presto/labels{/name}","releases_url":"https://api.github.com/repos/nezihyigitbasi/presto/releases{/id}","deployments_url":"https://api.github.com/repos/nezihyigitbasi/presto/deployments","created_at":"2014-06-10T19:14:21Z","updated_at":"2018-08-09T21:05:02Z","pushed_at":"2018-08-09T22:43:51Z","git_url":"git://github.com/nezihyigitbasi/presto.git","ssh_url":"git@github.com:nezihyigitbasi/presto.git","clone_url":"https://github.com/nezihyigitbasi/presto.git","svn_url":"https://github.com/nezihyigitbasi/presto","homepage":"http://prestodb.io/","size":95897,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"prestodb:master","ref":"master","sha":"7c1842671b29c79c2785bb8b46fbdadf4005c386","user":{"login":"prestodb","id":6882181,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY4ODIxODE=","avatar_url":"https://avatars0.githubusercontent.com/u/6882181?v=4","gravatar_id":"","url":"https://api.github.com/users/prestodb","html_url":"https://github.com/prestodb","followers_url":"https://api.github.com/users/prestodb/followers","following_url":"https://api.github.com/users/prestodb/following{/other_user}","gists_url":"https://api.github.com/users/prestodb/gists{/gist_id}","starred_url":"https://api.github.com/users/prestodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prestodb/subscriptions","organizations_url":"https://api.github.com/users/prestodb/orgs","repos_url":"https://api.github.com/users/prestodb/repos","events_url":"https://api.github.com/users/prestodb/events{/privacy}","received_events_url":"https://api.github.com/users/prestodb/received_events","type":"Organization","site_admin":false},"repo":{"id":5349565,"node_id":"MDEwOlJlcG9zaXRvcnk1MzQ5NTY1","name":"presto","full_name":"prestodb/presto","owner":{"login":"prestodb","id":6882181,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY4ODIxODE=","avatar_url":"https://avatars0.githubusercontent.com/u/6882181?v=4","gravatar_id":"","url":"https://api.github.com/users/prestodb","html_url":"https://github.com/prestodb","followers_url":"https://api.github.com/users/prestodb/followers","following_url":"https://api.github.com/users/prestodb/following{/other_user}","gists_url":"https://api.github.com/users/prestodb/gists{/gist_id}","starred_url":"https://api.github.com/users/prestodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prestodb/subscriptions","organizations_url":"https://api.github.com/users/prestodb/orgs","repos_url":"https://api.github.com/users/prestodb/repos","events_url":"https://api.github.com/users/prestodb/events{/privacy}","received_events_url":"https://api.github.com/users/prestodb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/prestodb/presto","description":"Distributed SQL query engine for big data","fork":false,"url":"https://api.github.com/repos/prestodb/presto","forks_url":"https://api.github.com/repos/prestodb/presto/forks","keys_url":"https://api.github.com/repos/prestodb/presto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/prestodb/presto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/prestodb/presto/teams","hooks_url":"https://api.github.com/repos/prestodb/presto/hooks","issue_events_url":"https://api.github.com/repos/prestodb/presto/issues/events{/number}","events_url":"https://api.github.com/repos/prestodb/presto/events","assignees_url":"https://api.github.com/repos/prestodb/presto/assignees{/user}","branches_url":"https://api.github.com/repos/prestodb/presto/branches{/branch}","tags_url":"https://api.github.com/repos/prestodb/presto/tags","blobs_url":"https://api.github.com/repos/prestodb/presto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/prestodb/presto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/prestodb/presto/git/refs{/sha}","trees_url":"https://api.github.com/repos/prestodb/presto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/prestodb/presto/statuses/{sha}","languages_url":"https://api.github.com/repos/prestodb/presto/languages","stargazers_url":"https://api.github.com/repos/prestodb/presto/stargazers","contributors_url":"https://api.github.com/repos/prestodb/presto/contributors","subscribers_url":"https://api.github.com/repos/prestodb/presto/subscribers","subscription_url":"https://api.github.com/repos/prestodb/presto/subscription","commits_url":"https://api.github.com/repos/prestodb/presto/commits{/sha}","git_commits_url":"https://api.github.com/repos/prestodb/presto/git/commits{/sha}","comments_url":"https://api.github.com/repos/prestodb/presto/comments{/number}","issue_comment_url":"https://api.github.com/repos/prestodb/presto/issues/comments{/number}","contents_url":"https://api.github.com/repos/prestodb/presto/contents/{+path}","compare_url":"https://api.github.com/repos/prestodb/presto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/prestodb/presto/merges","archive_url":"https://api.github.com/repos/prestodb/presto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/prestodb/presto/downloads","issues_url":"https://api.github.com/repos/prestodb/presto/issues{/number}","pulls_url":"https://api.github.com/repos/prestodb/presto/pulls{/number}","milestones_url":"https://api.github.com/repos/prestodb/presto/milestones{/number}","notifications_url":"https://api.github.com/repos/prestodb/presto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/prestodb/presto/labels{/name}","releases_url":"https://api.github.com/repos/prestodb/presto/releases{/id}","deployments_url":"https://api.github.com/repos/prestodb/presto/deployments","created_at":"2012-08-09T01:03:37Z","updated_at":"2018-08-09T22:16:08Z","pushed_at":"2018-08-09T23:03:14Z","git_url":"git://github.com/prestodb/presto.git","ssh_url":"git@github.com:prestodb/presto.git","clone_url":"https://github.com/prestodb/presto.git","svn_url":"https://github.com/prestodb/presto","homepage":"https://prestodb.io","size":96098,"stargazers_count":7880,"watchers_count":7880,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2686,"mirror_url":null,"archived":false,"open_issues_count":1338,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":2686,"open_issues":1338,"watchers":7880,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/prestodb/presto/pulls/11238"},"html":{"href":"https://github.com/prestodb/presto/pull/11238"},"issue":{"href":"https://api.github.com/repos/prestodb/presto/issues/11238"},"comments":{"href":"https://api.github.com/repos/prestodb/presto/issues/11238/comments"},"review_comments":{"href":"https://api.github.com/repos/prestodb/presto/pulls/11238/comments"},"review_comment":{"href":"https://api.github.com/repos/prestodb/presto/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/prestodb/presto/pulls/11238/commits"},"statuses":{"href":"https://api.github.com/repos/prestodb/presto/statuses/37bf0adaf78e88c0db0f5392cf6e118c98395056"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"dain"}}