Improve RTI classloader management - #101
Open
isaiahhaensel wants to merge 3 commits into
Open
Conversation
Adds a custom implementation of RtiFactoryFactory that ensures that all factory loading attempts use the same classloader, specifically the one that has been extended with the RTI HLA jar paths.
isaiahhaensel
marked this pull request as ready for review
July 27, 2026 06:03
Overhauls classpath extension to use separate classloaders for each RTI provider (thereby allowing switching providers at runtime) under a single base classloader (thereby ensuring that no attempt is made to load a given native library from more than one classloader).
isaiahhaensel
force-pushed
the
ih-rtiConsistentClasspath
branch
from
August 13, 2026 03:07
8f1900e to
42ccc80
Compare
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.
In HLA mode (RPR connection), Disco relies on extending the classpath with RTI provider libraries and uses an implementation of
RtiFactoryFactorywhich employs the current thread's context class loader.This currently contributes to three issues:
Only the context class loader of the thread that calls
OpsCenter#openbenefits from the classpath extension, so any calls toRtiFactoryFactory#getRtiFactoryfrom other threads (e.g., worker threads callingFederateAmbassador#receiveInteraction) may fail.Since it's impossible to remove paths from a classloader, switching RTI providers at runtime doesn't work because though you can add new paths, the classloader will still find the old ones first.
RTI providers (e.g., MAK) may use native libraries that cannot be loaded in more than one classloader. This means that if
DisApplication#startis initially called from one thread, then later from another thread, the second call will fail onRprConnection#initializeFederation's call toRtiFactoryFactory#getRtiFactory. See below for an example error when using the MAK RTI.A relatively non-complex solution to these issues is as follows:
On the FIRST startup, we store the current thread's context class loader, to use as a base
for extension (and to avoid daisy-chaining extended loaders).
We maintain a map, initially empty, associating RTI providers with extended classloaders.
On ANY startup, we retrieve or create a child classloader under the original stored one,
extend it with the paths for the configured RTI provider, and set it as the current thread's
classloader.
On ANY attempt to load an RtiFactory, we use the most recent extended classloader.
This effectively ensures that:
RtiFactory implementations are always available, irrespective of which thread the factory
method is called from.
Implementation classes from different RTI providers never conflict.
Native libraries are always loaded using the same classloader.
Additionally, and only indirectly related, this PR adds a check to avoid calling
RtiAmbassador#destroyFederationExecutionwhen disconnecting from a MAK RTI federation, because (at least currently) that call frequently either hangs, crashes the application, or crashes the JVM with anEXCEPTION_ACCESS_VIOLATIONatlibrti1516eJava64.dll+0xc0525. The MAK RTI is designed to clean up the federation execution on disconnect anyway, so the call is effectively redundant.