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

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

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • core
    • Jenkins 2.46

      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

       

          [JENKINS-44402] "Cancel shutdown" queue widget link inserted via AJAX does not work

          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

          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

          Oleg Nenashev added a comment -

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

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

          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 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

          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;">
          

          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 added a comment -

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

          Oleg Nenashev added a comment - Not working on it anymore. dnusbaum could you please submit a PR?

          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.

          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/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/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 added a comment -

          The fix has been integrated towards 2.114
          Thanks dnusbaum!

          Oleg Nenashev added a comment - The fix has been integrated towards 2.114 Thanks dnusbaum !

          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/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)

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

              Created:
              Updated:
              Resolved: