question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New class loading safety

See original GitHub issue

The 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:closed
  • Created 6 months ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
davideicardicommented, Mar 19, 2023

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.

0reactions
davideicardicommented, Mar 20, 2023

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 call Interpreter.Reference in one thread while calling Interpreter.Parse in another thread. This could result in unexpected errors. So technically Interpreter.Parse is thread safe, but only if used without changing the inner instance… I think this is quite common in .NET classes.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found