A pipeline throws random java.io.NotSerializableException

2,218 views
Skip to first unread message

Ivan Fernandez Calvo

unread,
Apr 5, 2019, 7:36:49 AM4/5/19
to Jenkins Users
Hi,

Let's see if someone can help me with a weird error that I randomly have, I have a job with about 60 stages in parallel, those stages run some tests all in the same way, randomly I saw the following stack trace, I guess it is related to a custom step I have in my pipeline shared library to make HTTP request. After reading similar issues I've checked that nothing assigned to a variable after exiting from the step to avoid a serialization exception so all variables are set to null before exits from it, but it does not help, I will try to remove all pipeline steps references and use @NonCPS

```
[2019-04-05T09:56:51.745Z] an exception which occurred:
[2019-04-05T09:56:51.745Z] 	in field com.cloudbees.groovy.cps.impl.BlockScopeEnv.locals
[2019-04-05T09:56:51.745Z] 	in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@45f33aac
[2019-04-05T09:56:51.745Z] 	in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
[2019-04-05T09:56:51.745Z] 	in object com.cloudbees.groovy.cps.impl.TryBlockEnv@75aefeb4
[2019-04-05T09:56:51.745Z] 	in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
[2019-04-05T09:56:51.745Z] 	in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@5365a8ac
[2019-04-05T09:56:51.745Z] 	in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
[2019-04-05T09:56:51.745Z] 	in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@293e6660
[2019-04-05T09:56:51.745Z] 	in field com.cloudbees.groovy.cps.impl.CallEnv.caller
[2019-04-05T09:56:51.746Z] 	in object com.cloudbees.groovy.cps.impl.FunctionCallEnv@5606e05
[2019-04-05T09:56:51.746Z] 	in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
[2019-04-05T09:56:51.746Z] 	in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@4fbdbabe
[2019-04-05T09:56:51.746Z] 	in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
[2019-04-05T09:56:51.746Z] 	in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@3d675ee3
[2019-04-05T09:56:51.746Z] 	in field com.cloudbees.groovy.cps.impl.CallEnv.caller
[2019-04-05T09:56:51.746Z] 	in object com.cloudbees.groovy.cps.impl.FunctionCallEnv@37e36233
[2019-04-05T09:56:51.746Z] 	in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
[2019-04-05T09:56:51.746Z] 	in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@51436a96
[2019-04-05T09:56:51.746Z] 	in field com.cloudbees.groovy.cps.impl.CallEnv.caller
[2019-04-05T09:56:51.746Z] 	in object com.cloudbees.groovy.cps.impl.FunctionCallEnv@5af50baa
[2019-04-05T09:56:51.746Z] 	in field com.cloudbees.groovy.cps.Continuable.e
[2019-04-05T09:56:51.746Z] 	in object org.jenkinsci.plugins.workflow.cps.SandboxContinuable@40e885e3
[2019-04-05T09:56:51.746Z] 	in field org.jenkinsci.plugins.workflow.cps.CpsThread.program
[2019-04-05T09:56:51.746Z] 	in object org.jenkinsci.plugins.workflow.cps.CpsThread@2e37df44
[2019-04-05T09:56:51.746Z] 	in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.threads
[2019-04-05T09:56:51.746Z] 	in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@2b8d184a
[2019-04-05T09:56:51.746Z] 	in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@2b8d184a
[2019-04-05T09:56:51.746Z] Caused: java.io.NotSerializableException: sun.net.www.protocol.https.HttpsURLConnectionImpl
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:926)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
[2019-04-05T09:56:51.746Z] 	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:344)
[2019-04-05T09:56:51.746Z] 	at java.util.HashMap.internalWriteEntries(HashMap.java:1790)
[2019-04-05T09:56:51.746Z] 	at java.util.HashMap.writeObject(HashMap.java:1363)
[2019-04-05T09:56:51.746Z] 	at sun.reflect.GeneratedMethodAccessor135.invoke(Unknown Source)
[2019-04-05T09:56:51.746Z] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[2019-04-05T09:56:51.746Z] 	at java.lang.reflect.Method.invoke(Method.java:498)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.reflect.JDKSpecific$SerMethods.callWriteObject(JDKSpecific.java:156)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:191)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1028)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
[2019-04-05T09:56:51.746Z] 	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:344)
[2019-04-05T09:56:51.746Z] 	at java.util.TreeMap.writeObject(TreeMap.java:2438)
[2019-04-05T09:56:51.746Z] 	at sun.reflect.GeneratedMethodAccessor541.invoke(Unknown Source)
[2019-04-05T09:56:51.746Z] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[2019-04-05T09:56:51.746Z] 	at java.lang.reflect.Method.invoke(Method.java:498)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.reflect.JDKSpecific$SerMethods.callWriteObject(JDKSpecific.java:156)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:191)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1028)
[2019-04-05T09:56:51.746Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
[2019-04-05T09:56:51.747Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1082)
[2019-04-05T09:56:51.747Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1040)
[2019-04-05T09:56:51.747Z] 	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:920)
[2019-04-05T09:56:51.747Z] 	at org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:58)
[2019-04-05T09:56:51.747Z] 	at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:111)
[2019-04-05T09:56:51.747Z] 	at org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverWriter.lambda$writeObject$0(RiverWriter.java:144)
[2019-04-05T09:56:51.747Z] 	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:136)
[2019-04-05T09:56:51.747Z] 	at org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverWriter.writeObject(RiverWriter.java:143)
[2019-04-05T09:56:51.747Z] 	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:482)
[2019-04-05T09:56:51.747Z] 	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:458)
[2019-04-05T09:56:51.747Z] 	at org.jenkinsci.plugins.workflow.cps.CpsStepContext$3.onSuccess(CpsStepContext.java:538)
[2019-04-05T09:56:51.747Z] 	at org.jenkinsci.plugins.workflow.cps.CpsStepContext$3.onSuccess(CpsStepContext.java:532)
[2019-04-05T09:56:51.747Z] 	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution$4$1.run(CpsFlowExecution.java:906)
[2019-04-05T09:56:51.747Z] 	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$1.run(CpsVmExecutorService.java:35)
[2019-04-05T09:56:51.747Z] 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[2019-04-05T09:56:51.747Z] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[2019-04-05T09:56:51.747Z] 	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
[2019-04-05T09:56:51.747Z] 	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
[2019-04-05T09:56:51.747Z] 	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
[2019-04-05T09:56:51.747Z] 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[2019-04-05T09:56:51.747Z] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[2019-04-05T09:56:51.747Z] 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[2019-04-05T09:56:51.747Z] 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[2019-04-05T09:56:51.747Z] 	at java.lang.Thread.run(Thread.java:748)
```

Reinhold Füreder

unread,
Apr 5, 2019, 7:50:44 AM4/5/19
to jenkins...@googlegroups.com

Hi Ivan,

 

Yep! I guess you are somewhere in your shared Jenkins pipeline library using sun.net.www.protocol.https.HttpsURLConnectionImpl – most likely because you are doing an URL request for e.g. a REST API call

=> extract that encapsulated logic into a dedicated method that returns something serializable (or primitive object) and annotate this method with @NonCPS

 

HTH Reinhold

Reply all
Reply to author
Forward
0 new messages