waterWang opened a new pull request, #19856:
URL: https://github.com/apache/druid/pull/19856

   Fixes #18253
   
   ## Problem
   GraalVM JS engine throws `IllegalStateException: Multi threaded access 
requested` when the same JavaScript context is accessed from multiple threads 
simultaneously. The `JavaScriptTieredBrokerSelectorStrategy` shares a single 
compiled JavaScript function across all broker routing threads, which triggers 
this error.
   
   ## Root cause
   `JavaScriptUtil.compileSelectorFunction()` creates a GraalVM `ScriptEngine` 
that is not thread-safe. The `fnSelector` field is lazily initialized with a 
non-atomic check-then-write pattern, and `fnSelector.apply()` is called from 
multiple Jetty handler threads without synchronization.
   
   ## Fix
   1. Add `synchronized` to `getBrokerServiceName()` to serialize all access to 
the shared GraalVM context
   2. Simplify the lazy initialization to a straightforward if-null check 
(protected by the synchronized block)
   
   ## Testing
   - Existing tests pass as-is (the test creates a single-threaded test, which 
is unaffected)
   - The fix prevents the `Multi threaded access requested` error in production 
Router deployments
   
   CC: @jtuglu1


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to