Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-44402

"Cancel shutdown" queue widget link inserted via AJAX does not work

    XMLWordPrintable

Details

    Description

      Steps to reproduce:

      1. Select "Jenkins" (drop-down arrow) -> "Manage Jenkins" -> "Prepare for Shutdown" (see https://issues.jenkins-ci.org/browse/JENKINS-38175?focusedCommentId=273918&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-273918)
      2. Click "cancel" link (left pane)

      Result: I get "POST is required for jenkins.model.Jenkins.doCancelQuietDown" (/cancelQuietDown). Clicking "Try POSTing" gives the 403 error:

      Problem accessing /cancelQuietDown. Reason: No valid crumb was included in the request

       

      Attachments

        Issue Links

          Activity

            owood Owen Wood created issue -
            owood Owen Wood made changes -
            Field Original Value New Value
            Link This issue relates to JENKINS-38175 [ JENKINS-38175 ]
            oleg_nenashev Oleg Nenashev added a comment -

            Cannot reproduce on 2.61.

            Likely it has been fixed by the security fixes in 2.46.2. CC danielbeck

            owood please try to reproduce the issue on 2.46.2. If the issue still appears, makes sense to investigate

            oleg_nenashev Oleg Nenashev added a comment - Cannot reproduce on 2.61. Likely it has been fixed by the security fixes in 2.46.2. CC danielbeck owood please try to reproduce the issue on 2.46.2. If the issue still appears, makes sense to investigate
            danielbeck Daniel Beck added a comment - - edited

            Reproduced on 2.46.2 (ci.jenkins.io). The key thing is to use the "(cancel)" link in the build queue widget that was added in an AJAX page update.

            These work:

            • Reload the page so that the link was already there on page load
            • Use the link in the same dropdown menu or on the /manage page
            danielbeck Daniel Beck added a comment - - edited Reproduced on 2.46.2 (ci.jenkins.io). The key thing is to use the "(cancel)" link in the build queue widget that was added in an AJAX page update. These work: Reload the page so that the link was already there on page load Use the link in the same dropdown menu or on the /manage page
            danielbeck Daniel Beck made changes -
            Summary Manage Jenkins - Prepare for Shutdown (via drop-down) gives 405 -> 403 "Cancel shutdown" queue widget link inserted via AJAX does not work
            oleg_nenashev Oleg Nenashev made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            oleg_nenashev Oleg Nenashev made changes -
            Assignee Oleg Nenashev [ oleg_nenashev ]
            oleg_nenashev Oleg Nenashev added a comment -

            Another lazy hack: Just navigate http://localhost:8080/jenkins/ajaxBuildQueue and run from there

            oleg_nenashev Oleg Nenashev added a comment - Another lazy hack: Just navigate http://localhost:8080/jenkins/ajaxBuildQueue  and run from there
            oleg_nenashev Oleg Nenashev added a comment -

            The issue happens because link.js fails. At least when you access the page directly:

            link.js:1 Uncaught ReferenceError: Behaviour is not defined
            at link.js:1

            oleg_nenashev Oleg Nenashev added a comment - The issue happens because link.js fails. At least when you access the page directly: link.js:1 Uncaught ReferenceError: Behaviour is not defined at link.js:1
            jamesdumay James Dumay made changes -
            Remote Link This issue links to "CloudBees Internal OSS-2269 (Web Link)" [ 18366 ]
            dnusbaum Devin Nusbaum added a comment - - edited

            I think that something needs to be modified in refreshPart and/or Behaviour#applySubtree so that any script tags included by st:adjunct in the refreshed subtree are executed.

            EDIT: It looks like refreshPart sets the new content by assigning to innerHTML, which does not execute any scripts in the new content. We'd need to look carefully at how replacePart is used before we start calling eval on scripts after setting innerHTML, but this is definitely the code that would need to be modified.

            Here is a simple patch that loads link.js unconditionally which fixes the issue:

            diff --git a/core/src/main/resources/lib/hudson/queue.jelly b/core/src/main/resources/lib/hudson/queue.jelly
            index 010fffb949..d38462218d 100644
            --- a/core/src/main/resources/lib/hudson/queue.jelly
            +++ b/core/src/main/resources/lib/hudson/queue.jelly
            @@ -46,6 +46,7 @@ THE SOFTWARE.
                 </j:otherwise>
               </j:choose>
               <l:pane title="${title}" width="2" id="buildQueue">
            +    <st:adjunct includes="lib.form.link.link"/>
                 <j:if test="${app.quietingDown}">
                   <tr>
                     <td class="pane" colspan="2" style="white-space: normal;">
            
            dnusbaum Devin Nusbaum added a comment - - edited I think that something needs to be modified in refreshPart and/or Behaviour#applySubtree so that any script tags included by st:adjunct in the refreshed subtree are executed. EDIT: It looks like refreshPart sets the new content by assigning to innerHTML , which does not execute any scripts in the new content. We'd need to look carefully at how replacePart is used before we start calling eval on scripts after setting innerHTML , but this is definitely the code that would need to be modified. Here is a simple patch that loads link.js unconditionally which fixes the issue: diff --git a/core/src/main/resources/lib/hudson/queue.jelly b/core/src/main/resources/lib/hudson/queue.jelly index 010fffb949..d38462218d 100644 --- a/core/src/main/resources/lib/hudson/queue.jelly +++ b/core/src/main/resources/lib/hudson/queue.jelly @@ -46,6 +46,7 @@ THE SOFTWARE. </j:otherwise> </j:choose> <l:pane title= "${title}" width= "2" id= "buildQueue" > + <st:adjunct includes= "lib.form.link.link" /> <j: if test= "${app.quietingDown}" > <tr> <td class= "pane" colspan= "2" style= "white-space: normal;" >
            oleg_nenashev Oleg Nenashev made changes -
            Status In Progress [ 3 ] Open [ 1 ]
            oleg_nenashev Oleg Nenashev made changes -
            Assignee Oleg Nenashev [ oleg_nenashev ]
            oleg_nenashev Oleg Nenashev added a comment -

            Not working on it anymore.
            dnusbaum could you please submit a PR?

            oleg_nenashev Oleg Nenashev added a comment - Not working on it anymore. dnusbaum could you please submit a PR?
            dnusbaum Devin Nusbaum made changes -
            Assignee Devin Nusbaum [ dnusbaum ]
            dnusbaum Devin Nusbaum made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            dnusbaum Devin Nusbaum made changes -
            Status In Progress [ 3 ] In Review [ 10005 ]
            dnusbaum Devin Nusbaum made changes -
            Remote Link This issue links to "jenkinsci/jenkins#3376 (Web Link)" [ 20339 ]
            dnusbaum Devin Nusbaum added a comment - - edited

            PR #3376 submitted with the above patch, which is a hack but does fix the issue. If anyone has some feedback or advice about fixing the root cause then I think that would be preferred.

            dnusbaum Devin Nusbaum added a comment - - edited PR #3376 submitted with the above patch, which is a hack but does fix the issue. If anyone has some feedback or advice about fixing the root cause then I think that would be preferred.

            Code changed in jenkins
            User: Devin Nusbaum
            Path:
            core/src/main/resources/lib/hudson/queue.jelly
            http://jenkins-ci.org/commit/jenkins/b2cdcf02186f83683169eae16423f8c9e6c579f7
            Log:
            JENKINS-44402 Workaround to make cancel shutdown work when loaded by AJAX

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Devin Nusbaum Path: core/src/main/resources/lib/hudson/queue.jelly http://jenkins-ci.org/commit/jenkins/b2cdcf02186f83683169eae16423f8c9e6c579f7 Log: JENKINS-44402 Workaround to make cancel shutdown work when loaded by AJAX

            Code changed in jenkins
            User: Oleg Nenashev
            Path:
            core/src/main/resources/lib/hudson/queue.jelly
            http://jenkins-ci.org/commit/jenkins/d534d5dc9dc09e1388dea80553e261015b072eb2
            Log:
            Merge pull request #3376 from dwnusbaum/JENKINS-44402

            JENKINS-44402 Make cancel shutdown link work when loaded via AJAX

            Compare: https://github.com/jenkinsci/jenkins/compare/be2dbec1cd14...d534d5dc9dc0

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Oleg Nenashev Path: core/src/main/resources/lib/hudson/queue.jelly http://jenkins-ci.org/commit/jenkins/d534d5dc9dc09e1388dea80553e261015b072eb2 Log: Merge pull request #3376 from dwnusbaum/ JENKINS-44402 JENKINS-44402 Make cancel shutdown link work when loaded via AJAX Compare: https://github.com/jenkinsci/jenkins/compare/be2dbec1cd14...d534d5dc9dc0
            oleg_nenashev Oleg Nenashev added a comment -

            The fix has been integrated towards 2.114
            Thanks dnusbaum!

            oleg_nenashev Oleg Nenashev added a comment - The fix has been integrated towards 2.114 Thanks dnusbaum !
            oleg_nenashev Oleg Nenashev made changes -
            Resolution Fixed [ 1 ]
            Status In Review [ 10005 ] Resolved [ 5 ]
            oleg_nenashev Oleg Nenashev made changes -
            Labels lts-candidate
            olivergondza Oliver Gondža made changes -
            Labels lts-candidate 2.107.3-fixed

            Code changed in jenkins
            User: Devin Nusbaum
            Path:
            core/src/main/resources/lib/hudson/queue.jelly
            http://jenkins-ci.org/commit/jenkins/6876eaa7f846279fbbc23cfd2ef353841a08d66f
            Log:
            JENKINS-44402 Workaround to make cancel shutdown work when loaded by AJAX

            (cherry picked from commit b2cdcf02186f83683169eae16423f8c9e6c579f7)

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Devin Nusbaum Path: core/src/main/resources/lib/hudson/queue.jelly http://jenkins-ci.org/commit/jenkins/6876eaa7f846279fbbc23cfd2ef353841a08d66f Log: JENKINS-44402 Workaround to make cancel shutdown work when loaded by AJAX (cherry picked from commit b2cdcf02186f83683169eae16423f8c9e6c579f7)

            People

              dnusbaum Devin Nusbaum
              owood Owen Wood
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: