{"action":"created","comment":{"url":"https://api.github.com/repos/jenkinsci/jenkins/pulls/comments/32415209","id":32415209,"diff_hunk":"@@ -1219,6 +1219,59 @@ public static void withLock(Runnable runnable) {\n         }\n     }\n \n+    /**\n+     * Some operations require to be performed with the {@link Queue} lock held. Use one of these methods rather\n+     * than locking directly on Queue in order to allow for future refactoring.\n+     * @param runnable the operation to perform.\n+     * @return {@code true} if the lock available and the operation performed. \n+     * @since 1.FIXME\n+     */\n+    public static boolean tryWithLock(Runnable runnable) {\n+        final Jenkins jenkins = Jenkins.getInstance();\n+        final Queue queue = jenkins == null ? null : jenkins.getQueue();\n+        if (queue == null) {","path":"core/src/main/java/hudson/model/Queue.java","position":39,"original_position":39,"commit_id":"6f343dc7c2f0c32e9eb1a0b5d588a2e7ad6f62ba","original_commit_id":"6f343dc7c2f0c32e9eb1a0b5d588a2e7ad6f62ba","user":{"login":"oleg-nenashev","id":3000480,"avatar_url":"https://avatars.githubusercontent.com/u/3000480?v=3","gravatar_id":"","url":"https://api.github.com/users/oleg-nenashev","html_url":"https://github.com/oleg-nenashev","followers_url":"https://api.github.com/users/oleg-nenashev/followers","following_url":"https://api.github.com/users/oleg-nenashev/following{/other_user}","gists_url":"https://api.github.com/users/oleg-nenashev/gists{/gist_id}","starred_url":"https://api.github.com/users/oleg-nenashev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oleg-nenashev/subscriptions","organizations_url":"https://api.github.com/users/oleg-nenashev/orgs","repos_url":"https://api.github.com/users/oleg-nenashev/repos","events_url":"https://api.github.com/users/oleg-nenashev/events{/privacy}","received_events_url":"https://api.github.com/users/oleg-nenashev/received_events","type":"User","site_admin":false},"body":"NIT: it should not really happen (?). Otherwise, we still have a risk of surprising behaviors on Jenkins startup","created_at":"2015-06-15T12:43:20Z","updated_at":"2015-06-15T12:43:20Z","html_url":"https://github.com/jenkinsci/jenkins/pull/1738#discussion_r32415209","pull_request_url":"https://api.github.com/repos/jenkinsci/jenkins/pulls/1738","_links":{"self":{"href":"https://api.github.com/repos/jenkinsci/jenkins/pulls/comments/32415209"},"html":{"href":"https://github.com/jenkinsci/jenkins/pull/1738#discussion_r32415209"},"pull_request":{"href":"https://api.github.com/repos/jenkinsci/jenkins/pulls/1738"}}},"pull_request":{"url":"https://api.github.com/repos/jenkinsci/jenkins/pulls/1738","id":37681098,"html_url":"https://github.com/jenkinsci/jenkins/pull/1738","diff_url":"https://github.com/jenkinsci/jenkins/pull/1738.diff","patch_url":"https://github.com/jenkinsci/jenkins/pull/1738.patch","issue_url":"https://api.github.com/repos/jenkinsci/jenkins/issues/1738","number":1738,"state":"open","locked":false,"title":"[FIXED JENKINS-28840] Deadlock between Queue.maintain and Executor.interrupt","user":{"login":"stephenc","id":209336,"avatar_url":"https://avatars.githubusercontent.com/u/209336?v=3","gravatar_id":"","url":"https://api.github.com/users/stephenc","html_url":"https://github.com/stephenc","followers_url":"https://api.github.com/users/stephenc/followers","following_url":"https://api.github.com/users/stephenc/following{/other_user}","gists_url":"https://api.github.com/users/stephenc/gists{/gist_id}","starred_url":"https://api.github.com/users/stephenc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stephenc/subscriptions","organizations_url":"https://api.github.com/users/stephenc/orgs","repos_url":"https://api.github.com/users/stephenc/repos","events_url":"https://api.github.com/users/stephenc/events{/privacy}","received_events_url":"https://api.github.com/users/stephenc/received_events","type":"User","site_admin":false},"body":"See [JENKINS-28840](https://issues.jenkins-ci.org/browse/JENKINS-28840)\r\n\r\nMore fun here:\r\n\r\n- All this originates from `Executor` extending `Thread`.\r\n- There is funky logic in the lock handling code of the JVM that makes assumptions\r\n  about how it might proceed with the lock when the thread holding the lock has its\r\n  interrupt flag set.\r\n- Really it would be better if `Executor` did not extend `Thread` as that way we wouldn't\r\n  have to deal with some of that complexity. But OTOH we are where we are and backwards\r\n  compatibility may make such a change not possible without a lot of breakage.\r\n- Fixing the issue at hand, firstly requires that interrupting a `Computer` happens with the\r\n  `Queue` lock held (to speed up tests we have `Jenkins.cleanUp` get the lock for all `Computer`s)\r\n  That prevents the `Queue` maintain thread from getting caught\r\n- Secondly, when removing an executor from a computer we process the removal while\r\n  holding the `Queue` lock, but we move the removal itself to a separate thread if we cannot\r\n  get the `Queue` lock in order to avoid deadlock.\r\n- Also add helper methods to wrap tasks to be performed while holding the lock\r\n  and a helper method for `Runnable`s that exposes the `tryLock` functionality\r\n\r\n@olivergondza hopefully this fixes the issue and it's not that I didn't run the flaky test case enough times on my machine. For back-porting to 1.609.2 we should obviously mark the new API methods in `Queue` as `@Restricted`\r\n\r\n@reviewbybees ","created_at":"2015-06-15T11:17:22Z","updated_at":"2015-06-15T12:43:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4fdf9e3d753be3dc39822cdfd8e07ba9ff124da7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jenkinsci/jenkins/pulls/1738/commits","review_comments_url":"https://api.github.com/repos/jenkinsci/jenkins/pulls/1738/comments","review_comment_url":"https://api.github.com/repos/jenkinsci/jenkins/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jenkinsci/jenkins/issues/1738/comments","statuses_url":"https://api.github.com/repos/jenkinsci/jenkins/statuses/6f343dc7c2f0c32e9eb1a0b5d588a2e7ad6f62ba","head":{"label":"stephenc:jenkins-28840","ref":"jenkins-28840","sha":"6f343dc7c2f0c32e9eb1a0b5d588a2e7ad6f62ba","user":{"login":"stephenc","id":209336,"avatar_url":"https://avatars.githubusercontent.com/u/209336?v=3","gravatar_id":"","url":"https://api.github.com/users/stephenc","html_url":"https://github.com/stephenc","followers_url":"https://api.github.com/users/stephenc/followers","following_url":"https://api.github.com/users/stephenc/following{/other_user}","gists_url":"https://api.github.com/users/stephenc/gists{/gist_id}","starred_url":"https://api.github.com/users/stephenc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stephenc/subscriptions","organizations_url":"https://api.github.com/users/stephenc/orgs","repos_url":"https://api.github.com/users/stephenc/repos","events_url":"https://api.github.com/users/stephenc/events{/privacy}","received_events_url":"https://api.github.com/users/stephenc/received_events","type":"User","site_admin":false},"repo":{"id":1399992,"name":"jenkins","full_name":"stephenc/jenkins","owner":{"login":"stephenc","id":209336,"avatar_url":"https://avatars.githubusercontent.com/u/209336?v=3","gravatar_id":"","url":"https://api.github.com/users/stephenc","html_url":"https://github.com/stephenc","followers_url":"https://api.github.com/users/stephenc/followers","following_url":"https://api.github.com/users/stephenc/following{/other_user}","gists_url":"https://api.github.com/users/stephenc/gists{/gist_id}","starred_url":"https://api.github.com/users/stephenc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stephenc/subscriptions","organizations_url":"https://api.github.com/users/stephenc/orgs","repos_url":"https://api.github.com/users/stephenc/repos","events_url":"https://api.github.com/users/stephenc/events{/privacy}","received_events_url":"https://api.github.com/users/stephenc/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/stephenc/jenkins","description":"Jenkins Continuous Integration Server","fork":true,"url":"https://api.github.com/repos/stephenc/jenkins","forks_url":"https://api.github.com/repos/stephenc/jenkins/forks","keys_url":"https://api.github.com/repos/stephenc/jenkins/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stephenc/jenkins/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stephenc/jenkins/teams","hooks_url":"https://api.github.com/repos/stephenc/jenkins/hooks","issue_events_url":"https://api.github.com/repos/stephenc/jenkins/issues/events{/number}","events_url":"https://api.github.com/repos/stephenc/jenkins/events","assignees_url":"https://api.github.com/repos/stephenc/jenkins/assignees{/user}","branches_url":"https://api.github.com/repos/stephenc/jenkins/branches{/branch}","tags_url":"https://api.github.com/repos/stephenc/jenkins/tags","blobs_url":"https://api.github.com/repos/stephenc/jenkins/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stephenc/jenkins/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stephenc/jenkins/git/refs{/sha}","trees_url":"https://api.github.com/repos/stephenc/jenkins/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stephenc/jenkins/statuses/{sha}","languages_url":"https://api.github.com/repos/stephenc/jenkins/languages","stargazers_url":"https://api.github.com/repos/stephenc/jenkins/stargazers","contributors_url":"https://api.github.com/repos/stephenc/jenkins/contributors","subscribers_url":"https://api.github.com/repos/stephenc/jenkins/subscribers","subscription_url":"https://api.github.com/repos/stephenc/jenkins/subscription","commits_url":"https://api.github.com/repos/stephenc/jenkins/commits{/sha}","git_commits_url":"https://api.github.com/repos/stephenc/jenkins/git/commits{/sha}","comments_url":"https://api.github.com/repos/stephenc/jenkins/comments{/number}","issue_comment_url":"https://api.github.com/repos/stephenc/jenkins/issues/comments{/number}","contents_url":"https://api.github.com/repos/stephenc/jenkins/contents/{+path}","compare_url":"https://api.github.com/repos/stephenc/jenkins/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stephenc/jenkins/merges","archive_url":"https://api.github.com/repos/stephenc/jenkins/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stephenc/jenkins/downloads","issues_url":"https://api.github.com/repos/stephenc/jenkins/issues{/number}","pulls_url":"https://api.github.com/repos/stephenc/jenkins/pulls{/number}","milestones_url":"https://api.github.com/repos/stephenc/jenkins/milestones{/number}","notifications_url":"https://api.github.com/repos/stephenc/jenkins/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stephenc/jenkins/labels{/name}","releases_url":"https://api.github.com/repos/stephenc/jenkins/releases{/id}","created_at":"2011-02-22T23:22:48Z","updated_at":"2015-04-27T13:30:13Z","pushed_at":"2015-06-15T11:12:38Z","git_url":"git://github.com/stephenc/jenkins.git","ssh_url":"git@github.com:stephenc/jenkins.git","clone_url":"https://github.com/stephenc/jenkins.git","svn_url":"https://github.com/stephenc/jenkins","homepage":"http://jenkins-ci.org/","size":85705,"stargazers_count":1,"watchers_count":1,"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":1,"default_branch":"master"}},"base":{"label":"jenkinsci:master","ref":"master","sha":"7e1a92157ddfaefe94a41d69d6d764c3a4260c6e","user":{"login":"jenkinsci","id":107424,"avatar_url":"https://avatars.githubusercontent.com/u/107424?v=3","gravatar_id":"","url":"https://api.github.com/users/jenkinsci","html_url":"https://github.com/jenkinsci","followers_url":"https://api.github.com/users/jenkinsci/followers","following_url":"https://api.github.com/users/jenkinsci/following{/other_user}","gists_url":"https://api.github.com/users/jenkinsci/gists{/gist_id}","starred_url":"https://api.github.com/users/jenkinsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenkinsci/subscriptions","organizations_url":"https://api.github.com/users/jenkinsci/orgs","repos_url":"https://api.github.com/users/jenkinsci/repos","events_url":"https://api.github.com/users/jenkinsci/events{/privacy}","received_events_url":"https://api.github.com/users/jenkinsci/received_events","type":"Organization","site_admin":false},"repo":{"id":1103607,"name":"jenkins","full_name":"jenkinsci/jenkins","owner":{"login":"jenkinsci","id":107424,"avatar_url":"https://avatars.githubusercontent.com/u/107424?v=3","gravatar_id":"","url":"https://api.github.com/users/jenkinsci","html_url":"https://github.com/jenkinsci","followers_url":"https://api.github.com/users/jenkinsci/followers","following_url":"https://api.github.com/users/jenkinsci/following{/other_user}","gists_url":"https://api.github.com/users/jenkinsci/gists{/gist_id}","starred_url":"https://api.github.com/users/jenkinsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenkinsci/subscriptions","organizations_url":"https://api.github.com/users/jenkinsci/orgs","repos_url":"https://api.github.com/users/jenkinsci/repos","events_url":"https://api.github.com/users/jenkinsci/events{/privacy}","received_events_url":"https://api.github.com/users/jenkinsci/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jenkinsci/jenkins","description":"Jenkins Continuous Integration Server","fork":true,"url":"https://api.github.com/repos/jenkinsci/jenkins","forks_url":"https://api.github.com/repos/jenkinsci/jenkins/forks","keys_url":"https://api.github.com/repos/jenkinsci/jenkins/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jenkinsci/jenkins/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jenkinsci/jenkins/teams","hooks_url":"https://api.github.com/repos/jenkinsci/jenkins/hooks","issue_events_url":"https://api.github.com/repos/jenkinsci/jenkins/issues/events{/number}","events_url":"https://api.github.com/repos/jenkinsci/jenkins/events","assignees_url":"https://api.github.com/repos/jenkinsci/jenkins/assignees{/user}","branches_url":"https://api.github.com/repos/jenkinsci/jenkins/branches{/branch}","tags_url":"https://api.github.com/repos/jenkinsci/jenkins/tags","blobs_url":"https://api.github.com/repos/jenkinsci/jenkins/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jenkinsci/jenkins/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jenkinsci/jenkins/git/refs{/sha}","trees_url":"https://api.github.com/repos/jenkinsci/jenkins/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jenkinsci/jenkins/statuses/{sha}","languages_url":"https://api.github.com/repos/jenkinsci/jenkins/languages","stargazers_url":"https://api.github.com/repos/jenkinsci/jenkins/stargazers","contributors_url":"https://api.github.com/repos/jenkinsci/jenkins/contributors","subscribers_url":"https://api.github.com/repos/jenkinsci/jenkins/subscribers","subscription_url":"https://api.github.com/repos/jenkinsci/jenkins/subscription","commits_url":"https://api.github.com/repos/jenkinsci/jenkins/commits{/sha}","git_commits_url":"https://api.github.com/repos/jenkinsci/jenkins/git/commits{/sha}","comments_url":"https://api.github.com/repos/jenkinsci/jenkins/comments{/number}","issue_comment_url":"https://api.github.com/repos/jenkinsci/jenkins/issues/comments{/number}","contents_url":"https://api.github.com/repos/jenkinsci/jenkins/contents/{+path}","compare_url":"https://api.github.com/repos/jenkinsci/jenkins/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jenkinsci/jenkins/merges","archive_url":"https://api.github.com/repos/jenkinsci/jenkins/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jenkinsci/jenkins/downloads","issues_url":"https://api.github.com/repos/jenkinsci/jenkins/issues{/number}","pulls_url":"https://api.github.com/repos/jenkinsci/jenkins/pulls{/number}","milestones_url":"https://api.github.com/repos/jenkinsci/jenkins/milestones{/number}","notifications_url":"https://api.github.com/repos/jenkinsci/jenkins/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jenkinsci/jenkins/labels{/name}","releases_url":"https://api.github.com/repos/jenkinsci/jenkins/releases{/id}","created_at":"2010-11-22T21:21:23Z","updated_at":"2015-06-15T06:54:55Z","pushed_at":"2015-06-15T11:59:02Z","git_url":"git://github.com/jenkinsci/jenkins.git","ssh_url":"git@github.com:jenkinsci/jenkins.git","clone_url":"https://github.com/jenkinsci/jenkins.git","svn_url":"https://github.com/jenkinsci/jenkins","homepage":"http://jenkins-ci.org/","size":419766,"stargazers_count":4184,"watchers_count":4184,"language":"Java","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":1858,"mirror_url":null,"open_issues_count":112,"forks":1858,"open_issues":112,"watchers":4184,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jenkinsci/jenkins/pulls/1738"},"html":{"href":"https://github.com/jenkinsci/jenkins/pull/1738"},"issue":{"href":"https://api.github.com/repos/jenkinsci/jenkins/issues/1738"},"comments":{"href":"https://api.github.com/repos/jenkinsci/jenkins/issues/1738/comments"},"review_comments":{"href":"https://api.github.com/repos/jenkinsci/jenkins/pulls/1738/comments"},"review_comment":{"href":"https://api.github.com/repos/jenkinsci/jenkins/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jenkinsci/jenkins/pulls/1738/commits"},"statuses":{"href":"https://api.github.com/repos/jenkinsci/jenkins/statuses/6f343dc7c2f0c32e9eb1a0b5d588a2e7ad6f62ba"}}}}