You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Global System.out/System.err redirection and static lock serialize all script runs JVM-wide #205
Script evaluation redirects the JVM-global standard streams, and script execution is serialized behind a static lock to keep that redirection safe. Both have process-wide side effects.
The BeanShell and Groovy interpreters call System.setOut/System.setErr for the whole JVM during evaluation (BeanShellScriptInterpreter.java:108-158, GroovyScriptInterpreter.java:96-123). While a script runs:
output written to System.out/System.err by unrelated threads in the same JVM (e.g. a logger writing to stderr, parallel build code) is silently captured into the script log; and
a concurrently running script on another thread would otherwise clobber the redirected stream.
ScriptRunner guards against concurrent evaluation with a static lock (ScriptRunner.java:43, used at ScriptRunner.java:225). Consequences:
All run(...) calls across allScriptRunner instances in the JVM are serialized, which is a bottleneck for parallel/CI builds that run hook scripts in multiple modules simultaneously.
Correctness of the global stream redirection depends entirely on every caller routing evaluation through that single static lock. Any future code path (or a caller invoking an interpreter directly) that evaluates outside the lock silently reintroduces cross-thread stream corruption.
Script output redirection affects only the current evaluation; unrelated threads keep writing to their own stdout/stderr, and concurrent script runs in the same JVM do not interfere.
Actual behavior
JVM-wide System.out/System.err redirection during evaluation captures other threads' output into the script log.
A single static lock serializes every ScriptRunner.run(...) call JVM-wide.
Suggested approach
Use a per-instance lock instead of the static lock so independent ScriptRunner instances do not serialize each other.
Redirect output via a stream that dispatches on the current thread/task (e.g. a ThreadLocal-based OutputStream) rather than mutating the process-global standard streams; restore the originals exactly as today in a finally block.
Activity
Route script output per thread instead of swapping System.out for the…