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

Running asynchronous code inside a @NonCPS method should fail cleanly

    • workflow-cps 2.71

      User-visible bit: throws an error

       

      Currently if you run a step with asynchronous execution (which is to say, almost all of them, since AbstractSynchronousNonBlockingStepExecution counts) inside a method marked @NonCPS, or otherwise not transformed (for example because of JENKINS-26481), you get bizarre results: the return value of the step becomes the return value of the method, regardless of what was supposed to happen in the rest of the method. This is because CpsCallableInvocation is thrown from DSL.invokeMethod and interrupts the method's execution.

      This is very confusing behavior. It would be better for CpsCallableInvocation.<init> to somehow detect that it is inside an untransformed method and throw a comprehensible error.

          [JENKINS-31314] Running asynchronous code inside a @NonCPS method should fail cleanly

          Jesse Glick created issue -
          Jesse Glick made changes -
          Link New: This issue is related to JENKINS-26481 [ JENKINS-26481 ]
          Jesse Glick made changes -
          Remote Link New: This issue links to "PR 233 (test only) (Web Link)" [ 13200 ]

          Code changed in jenkins
          User: Jesse Glick
          Path:
          aggregator/src/test/java/org/jenkinsci/plugins/workflow/SerializationTest.java
          http://jenkins-ci.org/commit/workflow-plugin/e5d9b321b7490d811cf3db5e4e93630c2f912412
          Log:
          JENKINS-31314 Demonstrating problem in test.
          The sample flow cannot possibly work, yet it runs without errors, just weird behavior.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: aggregator/src/test/java/org/jenkinsci/plugins/workflow/SerializationTest.java http://jenkins-ci.org/commit/workflow-plugin/e5d9b321b7490d811cf3db5e4e93630c2f912412 Log: JENKINS-31314 Demonstrating problem in test. The sample flow cannot possibly work, yet it runs without errors, just weird behavior.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          aggregator/src/test/java/org/jenkinsci/plugins/workflow/SerializationTest.java
          http://jenkins-ci.org/commit/workflow-plugin/59e6cf394ba79dea4db3dd2b99b7cca891341f16
          Log:
          Merge pull request #233 from jglick/test-JENKINS-31314

          JENKINS-31314 Demonstrating problem in test

          Compare: https://github.com/jenkinsci/workflow-plugin/compare/1b83632c5b8d...59e6cf394ba7

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: aggregator/src/test/java/org/jenkinsci/plugins/workflow/SerializationTest.java http://jenkins-ci.org/commit/workflow-plugin/59e6cf394ba79dea4db3dd2b99b7cca891341f16 Log: Merge pull request #233 from jglick/test- JENKINS-31314 JENKINS-31314 Demonstrating problem in test Compare: https://github.com/jenkinsci/workflow-plugin/compare/1b83632c5b8d...59e6cf394ba7
          Jesse Glick made changes -
          Remote Link New: This issue links to "groovy-cps #9 (Web Link)" [ 13724 ]
          Jesse Glick made changes -
          Link New: This issue is related to JENKINS-32863 [ JENKINS-32863 ]

          Code changed in jenkins
          User: Jesse Glick
          Path:
          aggregator/src/test/java/org/jenkinsci/plugins/workflow/SerializationTest.java
          http://jenkins-ci.org/commit/workflow-cps-plugin/7a03a4bcf2c08fa05afb7c5dd39ed73b28fef48c
          Log:
          JENKINS-31314 Demonstrating problem in test.
          The sample flow cannot possibly work, yet it runs without errors, just weird behavior.
          Originally-Committed-As: e5d9b321b7490d811cf3db5e4e93630c2f912412

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: aggregator/src/test/java/org/jenkinsci/plugins/workflow/SerializationTest.java http://jenkins-ci.org/commit/workflow-cps-plugin/7a03a4bcf2c08fa05afb7c5dd39ed73b28fef48c Log: JENKINS-31314 Demonstrating problem in test. The sample flow cannot possibly work, yet it runs without errors, just weird behavior. Originally-Committed-As: e5d9b321b7490d811cf3db5e4e93630c2f912412

          Code changed in jenkins
          User: Jesse Glick
          Path:
          aggregator/src/test/java/org/jenkinsci/plugins/workflow/SerializationTest.java
          http://jenkins-ci.org/commit/workflow-cps-plugin/f1b67bb381d1e55ccfe494c80e9d7ec3037d3e71
          Log:
          Merge pull request #233 from jglick/test-JENKINS-31314

          JENKINS-31314 Demonstrating problem in test
          Originally-Committed-As: 59e6cf394ba79dea4db3dd2b99b7cca891341f16

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: aggregator/src/test/java/org/jenkinsci/plugins/workflow/SerializationTest.java http://jenkins-ci.org/commit/workflow-cps-plugin/f1b67bb381d1e55ccfe494c80e9d7ec3037d3e71 Log: Merge pull request #233 from jglick/test- JENKINS-31314 JENKINS-31314 Demonstrating problem in test Originally-Committed-As: 59e6cf394ba79dea4db3dd2b99b7cca891341f16

          Thanks for the first explanation of what is goes wrong when I try writing any non-trivial CPS script. Usually I'm prepared to do the following:

          1. Define @NonCPS functions at the top level of the script, and only call them from the master node
          2. Use data processing in CPS very carefully on any non-master node (e.g. no closures, not even a regexp for string manipulation)
          3. Expect any feature of Groovy to fail at any time.

          Needless to say, that I have a hard time explaining people how to solve a problem with CPS, even if my solutions demonstrate that it can work. Maybe it would be easier to raise the priority of such issues if CPS didn't work at all.

          Thomas Goeppel added a comment - Thanks for the first explanation of what is goes wrong when I try writing any non-trivial CPS script. Usually I'm prepared to do the following: 1. Define @NonCPS functions at the top level of the script, and only call them from the master node 2. Use data processing in CPS very carefully on any non-master node (e.g. no closures, not even a regexp for string manipulation) 3. Expect any feature of Groovy to fail at any time. Needless to say, that I have a hard time explaining people how to solve a problem with CPS, even if my solutions demonstrate that it can work. Maybe it would be easier to raise the priority of such issues if CPS didn't work at all.

            jglick Jesse Glick
            jglick Jesse Glick
            Votes:
            16 Vote for this issue
            Watchers:
            27 Start watching this issue

              Created:
              Updated:
              Resolved: