#27429·jenkins

Chokepoint in Jelly parsing?

Author: olivierdagenaisCreated Sep 23, 2026Updated Sep 27, 2026

The symptoms

Last week, one of our Jenkins controllers stopped responding, probably because it was out of JVM memory as no web requests to the controller were being answered and in the hour before the non-responsiveness, our probe recorded the percentage of free JVM memory hurtling toward zero. Anyway, while it was stuck, I was able to request a JVM heap memory dump via jmap, which then allowed me to take a look at threads and their stack traces. That's when I noticed 127 threads handling the same GET request: 125 of those were BLOCKED (waiting to enter the mutex at ExpressionFactory.java:119) and 2 were RUNNABLE, with one of them holding the mutex for parser, and the other elsewhere in its rendering. In all, there were 185 instances of ExpressionFactory.java:119 in the thread dump!

Here's a (trimmed and anonymized) example of a blocked thread (the line numbers are from running on Jenkins 2.568.1):

"Handling GET /job/path/job/lion/buildHistory/ajax from 10.63.96.172 : Jetty (winstone)-2664195 HistoryPageFilter..." prio=5 tid=2664195 BLOCKED
    at org.apache.commons.jexl.ExpressionFactory.createNewExpression(ExpressionFactory.java:119)
    at org.apache.commons.jexl.ExpressionFactory.createExpression(ExpressionFactory.java:100)
    at hudson.ExpressionFactory2.createExpression(ExpressionFactory2.java:28)
    at org.kohsuke.stapler.jelly.CustomJellyContext$CustomXMLParser.createExpression(CustomJellyContext.java:168)
    at org.apache.commons.jelly.expression.CompositeExpression.parse(CompositeExpression.java:82)
    at org.apache.commons.jelly.TagLibrary.createExpression(TagLibrary.java:120)
    at org.apache.commons.jelly.parser.XMLParser.createTag(XMLParser.java:1104)
    at org.apache.commons.jelly.parser.XMLParser.startElement(XMLParser.java:686)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:518)
    at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:183)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:353)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2726)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:114)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:542)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:889)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:825)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1149)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
    at org.apache.commons.jelly.parser.XMLParser.parse(XMLParser.java:368)
    at org.apache.commons.jelly.JellyContext.compileScript(JellyContext.java:531)
    at org.kohsuke.stapler.jelly.CustomTagLibrary.loadJellyScript(CustomTagLibrary.java:157)
    at org.kohsuke.stapler.jelly.CustomTagLibrary.load(CustomTagLibrary.java:137)
    at org.kohsuke.stapler.jelly.CustomTagLibrary.load(CustomTagLibrary.java:124)
    at org.kohsuke.stapler.jelly.CustomTagLibrary.createTagScript(CustomTagLibrary.java:77)
    at org.apache.commons.jelly.parser.XMLParser.createTag(XMLParser.java:1091)
    at org.apache.commons.jelly.parser.XMLParser.startElement(XMLParser.java:686)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:518)
    at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:183)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:353)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2726)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:114)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:542)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:889)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:825)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1149)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
    at org.apache.commons.jelly.parser.XMLParser.parse(XMLParser.java:368)
    at org.apache.commons.jelly.JellyContext.compileScript(JellyContext.java:531)
    at org.kohsuke.stapler.jelly.JellyClassTearOff.parseScript(JellyClassTearOff.java:53)
    at org.kohsuke.stapler.jelly.JellyClassTearOff.parseScript(JellyClassTearOff.java:43)
    at org.kohsuke.stapler.AbstractTearOff.resolveScript(AbstractTearOff.java:183)
    at org.kohsuke.stapler.jelly.JellyClassTearOff.resolveScript(JellyClassTearOff.java:95)
    at org.kohsuke.stapler.jelly.JellyClassTearOff.resolveScript(JellyClassTearOff.java:43)
    at org.kohsuke.stapler.AbstractTearOff.loadScript(AbstractTearOff.java:218)
    at org.kohsuke.stapler.CachingScriptLoader.findScript(CachingScriptLoader.java:61)
    at org.kohsuke.stapler.jelly.IncludeTag.doTag(IncludeTag.java:138)
    at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:271)
    at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95)
    at org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:161)
    at org.apache.commons.jelly.tags.core.ForEachTag.doTag(ForEachTag.java:150)
    at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:271)
    at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95)
    at org.apache.commons.jelly.tags.core.CoreTagLibrary$2.run(CoreTagLibrary.java:105)
    at org.kohsuke.stapler.jelly.JellyViewScript.run(JellyViewScript.java:98)
    at org.kohsuke.stapler.jelly.IncludeTag.doTag(IncludeTag.java:174)
    at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:271)
    at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95)
    at org.apache.commons.jelly.tags.core.CoreTagLibrary$2.run(CoreTagLibrary.java:105)
    at org.kohsuke.stapler.jelly.JellyViewScript.run(JellyViewScript.java:98)
    at org.kohsuke.stapler.jelly.IncludeTag.doTag(IncludeTag.java:174)
    at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:271)
    at org.kohsuke.stapler.jelly.ReallyStaticTagLibrary$1.run(ReallyStaticTagLibrary.java:102)
    at org.apache.commons.jelly.tags.core.CoreTagLibrary$1.run(CoreTagLibrary.java:98)
    at org.kohsuke.stapler.jelly.CallTagLibScript$1.run(CallTagLibScript.java:100)
    at org.apache.commons.jelly.tags.define.InvokeBodyTag.doTag(InvokeBodyTag.java:91)
    at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:271)
    at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95)
    at org.kohsuke.stapler.jelly.CallTagLibScript$1.run(CallTagLibScript.java:100)
    at org.apache.commons.jelly.tags.define.InvokeBodyTag.doTag(InvokeBodyTag.java:91)
    at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:271)
    at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95)
    at org.apache.commons.jelly.tags.core.CoreTagLibrary$2.run(CoreTagLibrary.java:105)
    at org.kohsuke.stapler.jelly.CallTagLibScript.run(CallTagLibScript.java:121)
    at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95)
    at org.apache.commons.jelly.tags.core.CoreTagLibrary$1.run(CoreTagLibrary.java:98)
    at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95)
    at org.apache.commons.jelly.tags.core.CoreTagLibrary$2.run(CoreTagLibrary.java:105)
    at org.kohsuke.stapler.jelly.CallTagLibScript.run(CallTagLibScript.java:121)
    at org.apache.commons.jelly.tags.core.CoreTagLibrary$2.run(CoreTagLibrary.java:105)
    at org.kohsuke.stapler.jelly.JellyViewScript.run(JellyViewScript.java:98)
    at org.kohsuke.stapler.jelly.DefaultScriptInvoker.invokeScript(DefaultScriptInvoker.java:67)
    at org.kohsuke.stapler.jelly.DefaultScriptInvoker.invokeScript(DefaultScriptInvoker.java:55)
    at org.kohsuke.stapler.jelly.ScriptInvoker.execute(ScriptInvoker.java:62)
    at org.kohsuke.stapler.jelly.ScriptInvoker.execute(ScriptInvoker.java:42)
    at org.kohsuke.stapler.ScriptRequestDispatcher.forward(ScriptRequestDispatcher.java:102)
    at hudson.widgets.HistoryWidget.doAjax(HistoryWidget.java:278)
    (...129 other lines...)
    at java.lang.Thread.run(Thread.java:1583)

If the maintainers insist, I could attach the (anonymized) full thread dump (it's more than 7 MiB).

A theory: there's a chokepoint

With all these threads stuck at ExpressionFactory.java:119, naturally I went looking in the code and noticed that line 119 of that file was

java
synchronized (parser) {

...and that all accesses through this method were being funneled through a singleton, thus creating a chokepoint in JEXL expression parsing. This is a big deal for Jelly-based renderings (many Jenkins pages, fragments thereof and API endpoints use Jelly), as they can have many such expressions to parse, thus increasing the chances that threads from near-simultaneous requests can end up waiting on one another, possibly repeatedly.

While I don't know if the chokepoint caused the controller to run out of JVM heap space, it seems to me that this chokepoint is a flaw that makes a denial of service (DOS) easier to achieve, especially when/if the controller is already struggling to respond. It might only take a particularly slow request for one or more users to activate their browser's "refresh" action, thus spawning new threads that each try to parse expressions and making the problem worse.

Reproducing the chokepoint

GIVEN

  1. In a local copy of jenkinsci/jenkins at commit 81dc9a3e13a3ec4c4f74bedb772e3382b8de0760, I ran mvn -am -pl war,bom -Pquick-build clean install to build the WAR file.
  2. I ran mvn -pl war hpi:run to launch Jenkins locally.
  3. I created a freestyle job called "noise" (it runs a shell step that produces some console output) and queued 50 runs.
  4. I wrote the following Bash script, affectionately called hammer.sh:
    bash
    #!/bin/bash
    # front matter from https://devhints.io/bash
    set -o noclobber  # Avoid overlay files (echo "hi" > foo)
    set -o errexit    # Used to exit upon error, avoiding cascading errors
    set -o pipefail   # Fail the pipeline if any stage fails
    set -o nounset    # Exposes unset variables
    
    IFS=$'\n\t'
    trap_error() {
        echo "ERROR: ${BASH_SOURCE[1]} at about ${BASH_LINENO[0]}" >&2
    }
    set -o errtrace
    trap trap_error ERR
    # /front matter
    
    JENKINS_JVM_PID="${1:?Please provide the Jenkins JVM PID as the first parameter}"
    DEST_DIR="target/hammer"
    if [[ -d "${DEST_DIR}" ]]; then
        rm -rf "${DEST_DIR}"
    fi
    mkdir --parents "${DEST_DIR}"
    # Source - https://stackoverflow.com/a/8789815
    # Posted by David Webb, modified by community.
    # Retrieved 2026-09-17, License - CC BY-SA 3.0
    for i in $(seq -f "%03g" 1 100)
    do
        (
            for j in $(seq -f "%03g" 1 100)
            do
                echo "Attempt ${j}:" >> "${DEST_DIR}/${i}.log"
                curl --fail --silent "http://localhost:8080/jenkins/job/noise/buildHistory/ajax" -o "${DEST_DIR}/${i}.html" >> "${DEST_DIR}/${i}.log"
            done
        ) &
    done
    
    (
        for j in $(seq -f "%03g" 1 15)
        do
            jstack "${JENKINS_JVM_PID}" >> "${DEST_DIR}/jstack_${j}.log"
            sleep 1
        done
    ) &
    
    echo "Waiting for all jobs to complete..."
    wait
    echo "Done!"
    ...it launches 100 sub-shells that each "hammer" Jenkins by requesting the same page 100 times (via curl). While this is happening, the last parallel sub-shell invokes jstack 15 times, approximately once a second, to sample the stack traces of the threads during execution.

WHEN

I run time ./hammer.sh 1679996

THEN

The console output contains:

Waiting for all jobs to complete...
Done!

real    0m19.425s
user    0m35.234s
sys     0m34.515s

...and then running:

bash
grep -Pzo "Handling GET .+\n.+BLOCKED.+\n\tat .+\n" target/hammer/jstack*.log | tr '\000' '\n' > /path/to/blocked_00.txt

...yielded 229 instances of threads blocked on createNewExpression(), such as this one:

target/hammer/jstack_003.log:Handling GET /jenkins/job/noise/buildHistory/ajax from 127.0.0.1 : Jetty (winstone)-218" #218 [1681059] prio=5 os_prio=0 cpu=16.64ms elapsed=2.57s tid=0x00007f19a0001df0 nid=1681059 waiting for monitor entry  [0x00007f193e4dd000]
   java.lang.Thread.State: BLOCKED (on object monitor)
	at org.apache.commons.jexl.ExpressionFactory.createNewExpression(ExpressionFactory.java:119)

...there are other threads that were blocked (1023) in total, as it appears there was a lot of contention for parsing during the first ~3 seconds, then it appears other chokepoints were triggered and I can look into those later.

A potential solution: jexl2

To be fair, this chokepoint also existed in apache/commons-jexl 1.x that the Jenkins fork at jenkins/jexl was created from, so I started looking at jexl2, since it did not feature a chokepoint during parsing.

Upgrading the jenkinsci/jelly repository to use org.apache.commons:commons-jexl:2.1.1 (instead of the Jenkins fork of jexl) was farily straightforward, I just had to rename a variable called var in one of the tests as jexl2 considers it a keyword. I installed the 1.1-jenkins-20260419-SNAPSHOT version of jenkinsci/jelly in my local Maven repository, upreved the jelly.version in jenkinsci/stapler and installed the 999999-SNAPSHOT version of it into my local Maven repository as well, then turned to the Jenkins controller source code.

Upgrading Jenkins itself was a little more involved and seemed to work, until I hit a Jelly file that attempted to use var as an attribute, for example:

xml
<j:set var="name" value="${attrs.name?:attrs.var}"/>

...and the parser saw var and thought it was the keyword, despite the context suggesting otherwise. It turns out this was a known defect (see JEXL-304: Error parsing overview.limit.var, although I could not see how to get it to work in jexl2) and was fixed in version 3.2.

Another potential solution: jexl3

Upgrading the jenkinsci/jelly repository to use org.apache.commons:commons-jexl3:3.7.0 was a little more involved, as more keywords/reserved words were added, and there were tests trying to use variable names starting with switch. or case. or even default.. Installing the new SNAPSHOT jenkinsci/jelly in my local Maven repository, propagating it to jenkinsci/stapler and installing that were straightforward.

Upgrading Jenkins itself has been quite the adventure and this is the part where I poked my head up from the can of worms and asked myself if all this effort is worth it, since jexl3 is much more strict by default and there are a LOT of changes to the Jelly files I have to discover, troubleshoot and then fix.

Is this upgrade worth it?

As noted in the previous section, finding and fixing Jelly scripts for jexl3 compatibility is a lot of work. Many of those fixes/refactors are backward-compatible and could be posted as pull requests against Jenkins without the upgrades to jexl3, but I want to make sure that's time well-spent, with my pull requests being welcome.

I am attaching an example of the types of changes I am making to make Jenkins compatible with jexl3, which I have also tested on Jenkins as of commit 81dc9a3e13a3ec4c4f74bedb772e3382b8de0760: sample.diff.txt

Should I keep going?

Thanks!