[JIRA] (JENKINS-50100) Sleep throws after calling Jenkins.instance like getItemByFullName

277 views
Skip to first unread message

joesatriani323@gmail.com (JIRA)

unread,
Mar 11, 2018, 4:54:02 PM3/11/18
to jenkinsc...@googlegroups.com
Serghei Moret created an issue
 
Jenkins / Bug JENKINS-50100
Sleep throws after calling Jenkins.instance like getItemByFullName
Issue Type: Bug Bug
Assignee: Unassigned
Components: pipeline
Created: 2018-03-11 20:53
Labels: jenkins pipeline
Priority: Major Major
Reporter: Serghei Moret

Jenkins throws immediately while trying to sleep (it says sleeping but immediately throws, so the sleep doesn't happen). This happens only when the sleep command stays after Jenkins.instance.getItemByFullName method call. If I call sleep just one line before it sleeps as expected.

Stack trace:
[Pipeline] sleep
Sleeping for 10 sec
[Pipeline] End of Pipeline
an exception which occurred:
in field com.cloudbees.groovy.cps.impl.BlockScopeEnv.locals
in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@6e3fdbf0
in field com.cloudbees.groovy.cps.impl.CallEnv.caller
in object com.cloudbees.groovy.cps.impl.FunctionCallEnv@42c458b6
in field com.cloudbees.groovy.cps.Continuable.e
in object org.jenkinsci.plugins.workflow.cps.SandboxContinuable@689786e7
in field org.jenkinsci.plugins.workflow.cps.CpsThread.program
in object org.jenkinsci.plugins.workflow.cps.CpsThread@79ea6269
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.threads
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@ac4614b
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@ac4614b
Caused: java.io.NotSerializableException: org.jenkinsci.plugins.workflow.job.WorkflowJob
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
at org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
at org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:344)
at java.util.HashMap.internalWriteEntries(HashMap.java:1785)
at java.util.HashMap.writeObject(HashMap.java:1362)
at sun.reflect.GeneratedMethodAccessor124.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:273)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
at org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
at org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:344)
at java.util.TreeMap.writeObject(TreeMap.java:2438)
at sun.reflect.GeneratedMethodAccessor137.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:273)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:58)
at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:111)
at org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverWriter.lambda$writeObject$0(RiverWriter.java:144)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
at org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverWriter.writeObject(RiverWriter.java:143)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:467)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:443)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgramIfPossible(CpsThreadGroup.java:430)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:367)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:82)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:243)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:231)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
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:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

joesatriani323@gmail.com (JIRA)

unread,
Mar 11, 2018, 4:54:02 PM3/11/18
to jenkinsc...@googlegroups.com
Serghei Moret updated an issue
Change By: Serghei Moret
Jenkins throws immediately while trying to sleep (it says sleeping but immediately throws, so the sleep doesn't happen). This happens only when the sleep command stays after Jenkins.instance.getItemByFullName method call. If I call sleep just one line before it sleeps as expected.

Stack trace:
{code:java}
Finished: FAILURE {code}

andrew.bayer@gmail.com (JIRA)

unread,
Mar 11, 2018, 9:33:01 PM3/11/18
to jenkinsc...@googlegroups.com
Andrew Bayer resolved as Not A Defect
 

As the stacktrace shows, the problem is that you’ve called getItemByFullName and now have a WorkflowJob object in scope. So when the Pipeline is next serialized (which will happen eventually regardless but is always triggered by a sleep, things fail because WorkflowJob isn’t serializable. You should avoid calling things like Jenkins.instance.getItemByFullName in the first place, but if you must, you should do so in a method annotated with @NonCPS. Methods with that annotation can’t call Pipeline steps but aren’t serialized.

Change By: Andrew Bayer
Status: Open Resolved
Resolution: Not A Defect

joesatriani323@gmail.com (JIRA)

unread,
Mar 12, 2018, 5:56:02 AM3/12/18
to jenkinsc...@googlegroups.com
Serghei Moret commented on Bug JENKINS-50100
 
Re: Sleep throws after calling Jenkins.instance like getItemByFullName

Andrew Bayer Can you please consult more about @NonCPS (unfortunately for this job I need to get the list of jobs using getItemByFullName)? I've tried it but still getting the same. Here is what I do:

 

 

@NonCPS
def getJobs(project) {
 return Jenkins.instance.getItemByFullName(project)
}
def job = getJobs("monorepo-deploy")
println job
sleep 10

 

 

Stack trace looks the same as w/o @NonCPS
[Pipeline] echo
org.jenkinsci.plugins.workflow.job.WorkflowJob@63b1886d[ios-calabash-monorepo-deploy]


[Pipeline] sleep
Sleeping for 10 sec
[Pipeline] End of Pipeline
an exception which occurred:
in field com.cloudbees.groovy.cps.impl.BlockScopeEnv.locals

in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@5d7f9cec
in field com.cloudbees.groovy.cps.impl.CallEnv.caller
in object com.cloudbees.groovy.cps.impl.FunctionCallEnv@7a368476
in field com.cloudbees.groovy.cps.Continuable.e
in object org.jenkinsci.plugins.workflow.cps.SandboxContinuable@539f7260
in field org.jenkinsci.plugins.workflow.cps.CpsThread.program
in object org.jenkinsci.plugins.workflow.cps.CpsThread@28a02409
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.threads
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@6022fdd7
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@6022fdd7

joesatriani323@gmail.com (JIRA)

unread,
Mar 12, 2018, 5:57:02 AM3/12/18
to jenkinsc...@googlegroups.com
Serghei Moret reopened an issue
 
Change By: Serghei Moret
Resolution: Not A Defect
Status: Resolved Reopened

joesatriani323@gmail.com (JIRA)

unread,
Mar 12, 2018, 5:57:02 AM3/12/18
to jenkinsc...@googlegroups.com
Serghei Moret edited a comment on Bug JENKINS-50100
 
Re: Sleep throws after calling Jenkins.instance like getItemByFullName
[~abayer]  Thank you fro the quick answer. Can you please consult more about @NonCPS (unfortunately for this job I need to get the list of jobs using getItemByFullName)? I've tried it but still getting the same. Here is what I do:

 

 
{code:java}

@NonCPS
def getJobs(project) {
return Jenkins.instance.getItemByFullName(project)
}
def job = getJobs("monorepo-deploy")
println job
sleep 10
{code}

 

 

Stack trace looks the same as w/o @NonCPS
{code:java}
Finished: FAILURE {code}

andrew.bayer@gmail.com (JIRA)

unread,
Mar 12, 2018, 11:49:02 AM3/12/18
to jenkinsc...@googlegroups.com

@NonCPS basically means "don't run this method in the main Pipeline thread", which gets serialized for durability to work. So you should never let any objects that you don't know are serializable leak out of a @NonCPS method. In your example, I'd change it to:

@NonCPS
def getJobs(project) {
 return Jenkins.instance.getItemByFullName(project)?.toString()
}

...so that you're returning a String, and not a WorkflowJob. Once the WorkflowJob returned by Jenkins.instance.getItemByFullName(project) gets out of the @NonCPS method, you're going to end up hitting serialization issues.

joesatriani323@gmail.com (JIRA)

unread,
Mar 12, 2018, 12:08:01 PM3/12/18
to jenkinsc...@googlegroups.com

joesatriani323@gmail.com (JIRA)

unread,
Mar 12, 2018, 12:46:02 PM3/12/18
to jenkinsc...@googlegroups.com

joesatriani323@gmail.com (JIRA)

unread,
Mar 12, 2018, 12:47:01 PM3/12/18
to jenkinsc...@googlegroups.com
Serghei Moret closed an issue as Not A Defect
 
Change By: Serghei Moret
Status: Reopened Closed
Resolution: Not A Defect
Reply all
Reply to author
Forward
0 new messages