-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[mono] Fix the race condition issue of aot_module loading #103975
Conversation
src/mono/mono/mini/aot-runtime.c
Outdated
while (!(image->aot_module) && (count < 10)) { | ||
g_usleep (100); | ||
count++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't 100% correct (if the current thread is holding the loader lock, while another thread is trying to load some assemblies while loading hte AOT module, the other thread won't make progress). But it should handle 80% of the cases (where we just had a simple race, rather than a potential deadlock).
We decided this is ok.
The correct solution would be to make load_aot_module
safe to call from multiple threads at the same time using a lock-free "create and publish" strategy. But that will be a much harder rewrite because load_aot_module
has global effects (on the JIT info tables, for example)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to also set the module to AOT_MODULE_NOT_FOUND
here:
runtime/src/mono/mono/mini/aot-runtime.c
Lines 2086 to 2096 in c5e8f83
if (!sofile) { | |
// Maybe do these on more platforms ? | |
#ifndef HOST_WASM | |
if (mono_aot_only && !mono_use_interpreter && table_info_get_rows (&assembly->image->tables [MONO_TABLE_METHOD])) { | |
aot_name = g_strdup_printf ("%s%s", assembly->image->name, MONO_SOLIB_EXT); | |
g_error ("Failed to load AOT module '%s' ('%s') in aot-only mode.\n", aot_name, assembly->image->name); | |
g_free (aot_name); | |
} | |
#endif | |
return; | |
} |
/azp run runtime-ioslike |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-android |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-android |
/azp run runtime-ioslike |
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The android and ios/tvos failures are known. LGTM!
Is this issue going to be merged back on .net 8.0? I'm having an issue when IL stripping assemblies on Android |
@gabriel-kozma Yes, I've opened an PR to backport this fix to .NET8. However, this fix is on track to be shipped as part of .NET9 Preview7 as well. |
Fixes #103782