StackOverflowException in Declarative with when { expression {} }

443 views
Skip to first unread message

ST

unread,
Jan 15, 2018, 5:05:20 PM1/15/18
to Jenkins Users
I am seeing a StackOverflowException in org.jboss.marshalling.river.RiverMarshaller in a declarative Jenkins pipeline. The
interesting thing is that it occurs *only* just after having restarted the Jenkins instance. After building it once or twice,
the next build usually works fine. Also when waiting a few minutes after the Jenkins restart, the build seems to work fine.

I've boiled it down to this Jenkins Declarative Pipeline:

------------------
pipeline {
    
    agent any

    options {
        gitLabConnection('my-gitlab-connection')
        //skipDefaultCheckout() // if checkout should be done manually later one
        buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '185', numToKeepStr: ''))

        // Additionally this configuration is needed for git in Jenkins job configuration:
        //   "Additional behaviours" > "Checkout to specific local branch"
    }
    
    tools {
        jdk 'jdk9'
        maven 'maven3.5.x'
    }
    
    parameters {
        booleanParam(defaultValue: false, description: '', name: 'DO_MAVEN_RELEASE')
    }
    
    stages {
        stage('Maven build') {
            when {
                expression {
                    // Skip build if build is triggered by branch indexing (i.e. gitlab web hook) and commit
                    //  is from [maven-release-plugin], no need to build them.

                    // Inspired by https://jenkins.io/doc/pipeline/examples/#get-build-cause
                    triggeredByBranchIndexing = currentBuild.rawBuild.getCause(jenkins.branch.BranchIndexingCause) != null
                    grepExitStatus = sh(script: 'git log -1 | grep maven-release-plugin', returnStatus: true)
                    return !triggeredByBranchIndexing || grepExitStatus == 1 // grep exit status is 0 if a line is selected
                }
            }
            
            environment {
                m2RepoIdentifier = "${env.JOB_NAME}__${env.BRANCH_NAME}__${env.BUILD_NUMBER}"
            }
            
            steps {
                sleep 11
                script {
                    if (params.DO_MAVEN_RELEASE) {
                        echo "would mvn-release here, but skipping for debug reasons, ask SteThu."
                    } else {
                        sleep 10
                        echo "would mvn-build here, but skipping for debug reasons, ask SteThu."
                    }
                }
            }
        }
    }
    
    post {
        always {
            echo "Done with this pipeline, deleting workspace..."
            deleteDir()
        }
    }
}
------------------

When commenting out the when/expression section, I cannot reproduce the issue anymore, so I'm guessing it has 
to do with that groovy expression. But I can't see any serialization problems with those local variables, it is
a boolean and an exit status.

Anything wrong there? Or should I create an issue?

Below is the relevant part of the console log of the build.

The environment is:
-Jenkins 2.101 on Linux (standalone installation)
-one master node and one slave node, error occurs on both of them
-latest plugins installed (Pipeline Declarative Plugin v1.2.6)

Any input appreciated!
 stefan.


------------------
...
[PIPELINE INIT OUTPUT CROPPED]
...
Commit message: "Jenkinsfile: Comment out commands again for debugging"
 > git rev-list --no-walk c8587524261fcd7f8de8b0f8854089c7cca2eb48 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] timestamps
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Tool Install)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Maven build)
[Pipeline] sh
22:53:28 [workspace] Running shell script
22:53:28 + git log -1
22:53:28 + grep maven-release-plugin
[Pipeline] withEnv
[Pipeline] {
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] withEnv
[Pipeline] {
[Pipeline] End of Pipeline
[BFA] Scanning build for known causes...
[BFA] No failure causes found
[BFA] Done. 0s
java.lang.StackOverflowError
	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:115)
	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)
[the 4 lines above repeat around 100 times]	
	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.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.doWriteSerializableObject(RiverMarshaller.java:967)
	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.HashMap.internalWriteEntries(HashMap.java:1790)
	at java.util.HashMap.writeObject(HashMap.java:1363)
	at sun.reflect.GeneratedMethodAccessor50.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.writeObject(RiverWriter.java:140)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:459)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:435)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgramIfPossible(CpsThreadGroup.java:423)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:363)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(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

ST

unread,
Jan 15, 2018, 5:11:17 PM1/15/18
to Jenkins Users
Some additional info:

The Jenkins log file reports the same StackOverflowException, and in addition also reports this exception:
Jan 15, 2018 11:07:46 PM org.jenkinsci.plugins.workflow.job.WorkflowRun finish
INFO: MY_MULTIBRANCH-PIPELINE/master #253 completed: FAILURE
Jan 15, 2018 11:07:46 PM org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService reportProblem
WARNING: Unexpected exception in CPS VM thread: CpsFlowExecution[Owner[MY-MULTIBRANCH-PIPELINE/master/253:MY-MULTIBRANCH-PIPELINE/master #253]]
java.lang.NullPointerException
        at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:43)
        at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
        at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:331)
        at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(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)

Daniel Beck

unread,
Jan 15, 2018, 6:55:36 PM1/15/18
to jenkins...@googlegroups.com

> On 15. Jan 2018, at 23:05, ST <st.mail...@gmail.com> wrote:
>
> Any input appreciated!
>

Not sure but maybe pipeline steps like 'sh' aren't supposed to be used in when expression blocks?

ST

unread,
Jan 22, 2018, 4:36:12 PM1/22/18
to Jenkins Users
Ah, could be - anyone else can shed some light on whether using 'sh' in expression {} in declarative pipeline is fully supported or just happens to work sometimes?


pipeline {
    
    [...]
    
    stages {
        stage('Maven build') {
            when {
                expression {
                    triggeredByBranchIndexing = currentBuild.rawBuild.getCause(jenkins.branch.BranchIndexingCause) != null
                    grepExitStatus = sh(script: 'git log -1 | grep maven-release-plugin', returnStatus: true)
                    return !triggeredByBranchIndexing || grepExitStatus == 1 // grep exit status is 0 if a line is selected
                }
            }

[...]

}
}
}


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/F3101214-5ACA-4833-B28C-2B1D67755C59%40beckweb.net.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages