Split MEOS initialisation in MeosThread into process-once and per-thread - #43
Merged
estebanzimanyi merged 1 commit intoJul 23, 2026
Conversation
MeosThread ran the full meos_initialize() on every executor thread. That is unsafe: meos_initialize() re-installs the process-global error handler (MEOS's exiting default), so one thread's initialisation momentarily replaces the no-exit handler that every other thread relies on to turn a MEOS error into a Java exception. A MEOS error raised in that window ends the JVM with exit(EXIT_FAILURE). MEOS setup has two lifetimes: the allocator and error handler are process-global, while the timezone and collation caches are thread-local (the PROJ, GEOS and GSL contexts are thread-local too and created lazily on first use). Install the process-global part once per JVM through a holder whose class initialiser runs under the JVM class-initialisation lock, and run only meos_initialize_timezone and meos_initialize_collation per thread. No thread re-installs the handler, so the window is closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MeosThread initialises MEOS by running the full
meos_initialize()on every executor thread. That is unsafe under concurrency:meos_initialize()re-installs the process-global error handler (MEOS's exiting default), so one thread's initialisation momentarily replaces the no-exit handler that every other thread relies on to turn a MEOS error into a Java exception. A MEOS error raised in that window ends the JVM withexit(EXIT_FAILURE)— silently, with no stack trace.MEOS setup has two lifetimes:
proj_get_context/geos_get_contextcall the static per-thread initialisers on demand).This change installs the process-global part once per JVM through a holder whose class initialiser runs under the JVM class-initialisation lock, and runs only
meos_initialize_timezone+meos_initialize_collationper thread. No thread re-installs the handler, so the reset window is closed; PROJ/GEOS/GSL still initialise lazily per thread, so spatial UDFs are unaffected.ensureReady()is unchanged, so every generated UDF entry point still guards correctly.