Improve thread safety for pkl:base (#1719)

Stdlib modules are singletons that are shared across multiple evaluators.
This improves thread safety by evaluating its `output.bytes` during
initialization, which initializes truffle nodes (e.g. TypeTestNode),
and also initializes the member cache of the module output of `pkl:base`
This commit is contained in:
Daniel Chao
2026-07-06 11:19:29 -07:00
committed by GitHub
parent 2ec83198f5
commit eaf73af247
2 changed files with 42 additions and 4 deletions
@@ -772,6 +772,23 @@ class EvaluatorTest {
.doesNotThrowAnyException()
}
@Test
fun `concurrent evals`() {
val exceptions = mutableListOf<Throwable>()
val threads =
(0..10).map {
Thread { Evaluator.preconfigured().use { ev -> ev.evaluateOutputText(text("foo = 1")) } }
.also { t ->
t.uncaughtExceptionHandler = Thread.UncaughtExceptionHandler { _, e ->
synchronized(exceptions) { exceptions.add(e) }
}
t.start()
}
}
for (t in threads) t.join()
exceptions.firstOrNull()?.let { throw it }
}
private fun checkModule(module: PModule) {
assertThat(module.properties.size).isEqualTo(2)
assertThat(module.getProperty("name")).isEqualTo("pigeon")