Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-26481] More clearly report problem passing closures to binary methods #15

Merged
merged 7 commits into from
Jun 10, 2016

Conversation

jglick
Copy link
Member

@jglick jglick commented Jun 6, 2016

JENKINS-26481

Tries to improve diagnostics until cloudbees/groovy-cps#24 can be fixed.

Before this patch, SerializationTest.eachClosure fails with cryptic script behavior:

Started
[Pipeline] node
Running on master in /tmp/junit3096297553890442745/junit8071484631883149575/workspace/demo
[Pipeline] {
[Pipeline] writeFile
[Pipeline] semaphore
[Pipeline] readFile
[Pipeline] echo
a
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

Note that there is no error in the build, it just does not run correctly. After the patch, the build fails:

Started
[Pipeline] node
Running on master in /tmp/junit8559386618399120809/junit4301051117364074727/workspace/demo
[Pipeline] {
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.UnsupportedOperationException: Calling public static java.lang.Object org.codehaus.groovy.runtime.DefaultGroovyMethods.each(java.lang.Object,groovy.lang.Closure) on a CPS-transformed closure is not yet supported (JENKINS-26481); encapsulate in a @NonCPS method, or use Java-style loops
    at org.jenkinsci.plugins.workflow.cps.GroovyClassLoaderWhitelist.checkJenkins26481(GroovyClassLoaderWhitelist.java:84)
    at org.jenkinsci.plugins.workflow.cps.GroovyClassLoaderWhitelist.permitsStaticMethod(GroovyClassLoaderWhitelist.java:54)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:83)
    at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:149)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:146)
    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:15)
    at WorkflowScript.run(WorkflowScript:2)
    at ___cps.transform___(Native Method)
    at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:55)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:106)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:79)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:40)
    at com.cloudbees.groovy.cps.Next.step(Next.java:58)
    at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:32)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:29)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:106)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:29)
    at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:164)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:276)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$000(CpsThreadGroup.java:78)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:185)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:183)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:47)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE

@reviewbybees esp. @kohsuke

… a CPS-transformed closure to a binary method.
…ally requested a Closure, and is thus likely to try to call it.
}
});
}

@Ignore("TODO JENKINS-31314: calls writeFile just once, echoes null (i.e., return value of writeFile), then succeeds")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still fails with the same behavior.

@abayer
Copy link
Member

abayer commented Jun 9, 2016

🐝 Happy to see this!

private final ClassLoader scriptLoader;

public GroovyClassLoaderWhitelist(GroovyClassLoader scriptLoader) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not expect other plugins to have classes in the org.jenkinsci.plugins.workflow.cps package, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.

@oleg-nenashev
Copy link
Member

🐝 if there is no compatibility risk

@oleg-nenashev
Copy link
Member

re- 🐝

@abayer
Copy link
Member

abayer commented Jun 9, 2016

re 🐝 as well.

@jglick
Copy link
Member Author

jglick commented Jun 9, 2016

Will wait to see if @kohsuke has any concerns about this. Obviously it passes local tests, but there is some risk of inadvertently failing legitimate, previously working calls.

@jglick
Copy link
Member Author

jglick commented Jun 9, 2016

@kohsuke asks for confirmation that this does not break usages of closures in global libraries, and I guess I would add load. I think it should be fine, as these use GroovyClassLoader, but it is worth verifying in a test.

@jglick
Copy link
Member Author

jglick commented Jun 9, 2016

And I checked that workflow-cps-global-lib tests pass against this PR, including WorkflowLibRepositoryTest.userDefinedGlobalVariable which passes a CPS-transformed closure to a global variable. If I patch it as

diff --git a/src/test/java/org/jenkinsci/plugins/workflow/cps/global/WorkflowLibRepositoryTest.java b/src/test/java/org/jenkinsci/plugins/workflow/cps/global/WorkflowLibRepositoryTest.java
index b814207..b1845b8 100644
--- a/src/test/java/org/jenkinsci/plugins/workflow/cps/global/WorkflowLibRepositoryTest.java
+++ b/src/test/java/org/jenkinsci/plugins/workflow/cps/global/WorkflowLibRepositoryTest.java
@@ -116,6 +116,7 @@ public class WorkflowLibRepositoryTest {
                         "  body.resolveStrategy = Closure.DELEGATE_FIRST",
                         "  body.delegate = config",
                         "  body()",
+                        "  [config.title].each {x -> echo x}",
                         "  echo 'title was '+config.title",
                         "}")
                         , "\n"));

then it fails with the expected UnsupportedOperationException.

@abayer
Copy link
Member

abayer commented Jun 9, 2016

re-re-:bee:!

@jglick jglick merged commit 0043928 into jenkinsci:master Jun 10, 2016
@jglick jglick deleted the report-JENKINS-26481 branch June 10, 2016 12:53
jglick added a commit that referenced this pull request Jun 10, 2016
jglick added a commit that referenced this pull request Jun 10, 2016
dwnusbaum pushed a commit to dwnusbaum/workflow-cps-plugin that referenced this pull request Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants