[release/8.0-staging] [Mono] Fix the race condition issue of aot_module loading#104918
Merged
fanyang-mono merged 1 commit intodotnet:release/8.0-stagingfrom Jul 23, 2024
Merged
Conversation
Contributor
|
Friendly reminder that today Monday July 15th is Code Complete day at 4pm PT, which is the deadline to get this included in the August Release. |
Member
Author
|
@carlossanlop Thanks for the reminder. It is okay to ship this in the September release. |
lambdageek
approved these changes
Jul 15, 2024
jeffschwMSFT
approved these changes
Jul 16, 2024
Member
jeffschwMSFT
left a comment
There was a problem hiding this comment.
lgtm. we will take for consideration in 8.0.x
Member
Author
|
CI failure on |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Backport of #103975 to release/8.0
/cc @fanyang-mono
Customer Impact
Prior to this change, Maui Android customer's app would run into
Invalid IL codeerror when settingAndroidStripILAfterAOT=true. The customer's app would either hitInvalidProgramExceptionor crash completely. The customers reported the issue via #103782 and #104156When setting
AndroidStripILAfterAOT=true, the IL code for the AOT'ed methods would be removed. As a result, JIT would fail with an error likeInvalid IL code, if the runtime attempts to do so. Usually, when a method was AOT compiled, Mono runtime would use it instead of attempting to JIT it. What happened to this customer reported scenario was thatmono_aot_get_methodraced withload_aot_module- one thread attemptted to readMonoImage:aot_modulewhile the other thread was still loading the aot module.MonoImage:aot_modulecontained the information of where the AOT'ed code lives. When it wasn't fully loaded, Mono runtime thought it didn't exist. However, this race condition only happened when two threads were trying to invoke methods from the same assembly, which also happened to be not loaded yet. It is often related to the usage of reflection.Before this PR, there wasn't a way to tell if an aot module was loaded but not found or wasn't loaded at all. This PR introduced a way to differentiate it. Now when
mono_aot_get_methodsees that the aot module wasn't loaded yet, it will wait a little bit and try again.Testing
Manually validated the problematic maui Android app reported in the original issue (#103782). It works correctly now.
Risk
Moderate risk. The race condition that this PR is fixing happens very rarely. So far it only happened to a handful of Maui Android customers. This PR doesn't change the behavior when there isn't a race condition, which is the majority of the case. Additionally, we had monitored microbenchmarks results for two weeks and didn't see any performance regressions caused by this change.