New class loading safety
See original GitHub issueThe most common failure for our unit tests is a DynamicExpresso bug. It’s quite annoying too.
Every usage of DynamicExpresso is guarded by locks in our case however unit tests still fail. There appears to be a race condition in type loading, something that looks to require a global (app domain?) lock internally.
[xUnit.net 00:00:02.12] DynamicExpresso.Exceptions.ParseException : No applicable constructor exists in type 'X4BFlow.Test.Nf9.TestTemplatePrototype+TemplateTest' (at index 55).
[xUnit.net 00:00:02.12] Stack Trace:
[xUnit.net 00:00:02.12] at DynamicExpresso.Parsing.Parser.ParseNew()
We can make this happen by running tests in xunit which occur in parallel between test fixtures. One interpreter per test case, however the loading of types on first use may still occur in parallel.
Issue Analytics
- State:
- Created 6 months ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
The Primordial Class Loader
First of all, lazy loading means that classes are loaded on demand and at the last moment possible. Second, dynamic class loading maintains...
Read more >Class Loading Reference
A ClassLoader is said to be 'transformer safe' if it is safe to load classes in the class loader before the transformers are...
Read more >Class Loader API Modifications for Deadlock Fix
ClassLoader uses a class-name-based locking scheme. Remove all synchronization on the class loader lock. Ensure that critical sections are safe ...
Read more >Class Loaders in Java
Class loaders are responsible for loading Java classes dynamically to the JVM (Java Virtual Machine) during runtime.
Read more >Safety of Implementation - Learning Java, 4th Edition [Book]
A class loader handles loading classes from local storage or the network. At the innermost level, all system security ultimately rests on the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think that the problem is that you can have one thread that modify the Interpreter (calling Reference, …) While another thread is calling Compile. This is not supported. For unit testing I suggest to not share the instances. For real usage code I suggest to have an initialization phase where you configure it, and then call only read only functions.
I will close the issue, but if you need further assistence feel free to re-open it.
Just a clarification regarding thread safety: All the
Interpreter
functions that do not modify the instance can be called by multiple threads at the same time. But you cannot callInterpreter.Reference
in one thread while callingInterpreter.Parse
in another thread. This could result in unexpected errors. So technicallyInterpreter.Parse
is thread safe, but only if used without changing the inner instance… I think this is quite common in .NET classes.