-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Race condition during module compilation engine #2190
Comments
please provide the reproducer, otherwise we can't verify |
wazevo
engine
closing until you give us the minimal repro. Note that executing a module instance concurrently is inherently unsafe and not possible unless you use the threading proposal enabled + your binary is compiled in that way. |
As described in this comment - a compilation engine is getting re-used/shared between runtimes. The |
I'd be glad to provide example(s), propose a fix etc. Just want to see this one getting resolved 😊 |
A bit of background to the story - issue has been observed while working on a high-level library that steps on top of |
@mathetake - update of my previous comment (was on my phone, on my way to work) As described in this comment - a compilation engine is getting re-used/shared between runtimes. The As the "callstack" suggests - there's no logic to govern access to the said map and the said map is not thread-safe. As a result - a race condition occurs as soon as you try and use a single cache instance among multiple runtime instances and you try to load/execute modules concurrently. It is evident that we're talking about a bug in here. If you take a look at the implementation of |
A potential fix for the problem is to create a "private" function to check if a module has been compiled already. Something like:
and replace the direct access to the map in here with calling the said function. |
Describe the bug
In the
wazevo
engine implementation there're multiple places where Go maps are used (not sync.Map). When trying to run modules in parallel (different runtime instances, shared cache) - race conditions occur and execution is aborted withfatal error: concurrent map read and map write
To Reproduce
Try and run the same command module in a for loop, creating a new runtime for each iteration. Delegate load & execution to a new Go routine for each execution attempt.
Expected behavior
No race condition / panics shall occur when running modules in parallel with a common/shared cache.
Screenshots
N/A
Environment (please complete the relevant information):
Additional context
N/A
The text was updated successfully, but these errors were encountered: