-
Notifications
You must be signed in to change notification settings - Fork 532
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
InvalidProgramException (invalid IL code), VerificationException, and SIGSEGV when executing LINQ queries simultaneously using thread pool #1483
Comments
This remains an issue on Visual Studio 15.7.0 with Xamarin 4.10.0.442 and Xamarin.Android SDK 8.3.0.19. Various crashes, as initially described above. |
I can confirm for VS 15.7.3 with various Android devices. |
@rgroenewoudt Thank you for confirming the issue, and also for trying on the latest Visual Studio release. |
I have the same issue on VS 15.7.5 using EF Core extension methods. For example:
Causes ~ 1 crash out of 3 runs. More Include I do more often crash happens. 3 includes crashes app all the time on my galaxy note 8. |
VS 15.8, debug mode, EFCore 2.0.1 and 2.1.1 Run 1:
Run 2:
|
I can cofirm this. VS 15.8, EFCore 2.1.2
at (wrapper managed-to-native) System.Delegate.CreateDelegate_internal(System.Type,object,System.Reflection.MethodInfo,bool) Any updates? |
Still reproducible with VS 15.9 and EFCore 2.1.4.
|
Still reproducible with VS 2019.1 and EFCore 2.2.4 |
Same issue here, EF Core 2.2.4 and latest Xamarin.Android. |
Does anyone from Xamarin even look at these, open since 27 March 2018...? |
Related issues on the Mono side: mono/mono#12626, possibly also mono/mono#14080. Also https://github.com/mono/mono/blob/d5b374bb51a07bf3525d63b4cef6ad6979c27d07/netcore/CoreFX.issues.rsp#L189-L193 |
@lambdageek Thanks for connecting this to the other issues. Perhaps the repro here could be helpful as mono/mono#12626 mentions the issue as "unreproducible". The repro on this issue demonstrates the problems most of the time. |
@lambdageek can we close this one? |
Steps to Reproduce
Download, extract, and load the sample solution (zip file below) in a current version of Visual Studio. I tried with Visual Studio 15.6.4 for PC and Visual Studio 2017 for Mac version 7.5 Preview 1.
Build and run the Android app project, targeting a real Android device.
EFCoreBug5456.Android.zip
Expected Behavior
The sample app shouldn't crash when calling the test method during startup.
QueryBugsInMemoryTest.Repro5456_multi_level_include_group_join_is_per_query_context_async()
is a test method from Entity Framework Core v2.0.2's test suite. This test method passes on both .NET Framework and .NET Core. I happened upon this issue as I've been assessing how a meaningful subset of EF Core's unit tests would perform with Xamarin.iOS and Xamarin.Android.Actual Behavior
Most (90%) of the time, the app crashes. Crashes include exceptions
System.InvalidProgramException
(most frequent) andSystem.Security.VerificationException
. One time the app was seen aborting with "Got a SIGSEGV while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application."Examples of
System.InvalidProgramException
invalid IL in code include:method body is empty
(most frequent),IL_0022: brtrue IL_00e9
,IL_0021: ldelem.ref
,IL_0083: brtrue IL_0088
,IL_0028: callvirt 0x0000000b
.An example of
System.Security.VerificationException
isInvalid instruction target e9 occurred
.Results reported when sample app run 10 times on a Moto G5 Plus
Results reported when sample app run 10 times on a Google Nexus 7 (2013)
Example of SIGSEGV abort with mono runtime stack trace
Of note is that the test executes in-memory LINQ queries simultaneousy using the thread pool via TPL's
Parallel.For()
. The location of these exceptions vary (especially in depth), but always within in aSystem.Object:(wrapper dynamic-method) object:lambda_method
. The multiple locations, types of exceptions reported, and transient nature of the issue has me guessing there is corruption due to lack of thread safety in some part of IL code generation for lambda methods.The issue has been observed occurring less frequently when lowering either the number of iterations performed by
Parallel.For()
, as well when limiting the maximum number of threads in the managed thread pool. The issue does not occur when employing a conventionalfor()
, nor when limiting theParallel.For()
to a single thread withParallelOptions { MaxDegreeOfParallelism = 1 }
.Potential Impact
While this is one issue from a broad test suite¹, the test originates from multiple cases of real world code from multiple developers, although no cases were in the context of a mobile application.
Yet it is highly conceivable that a mobile app could execute complex lamdba expressions simultaneously — especially as practices tend toward improving performance by taking advantage of multicore on slower power-efficient mobile CPUs.
A developer writing deliberately thread-safe code could still see failures due to this internal runtime issue.
¹ (and for the record, Xamarin.Android otherwise performs very well, as I'll share here soon-ish.)
Version Information
Log File
Here's output from
adb logcat -d
after a failed run: adb-logcat-d.txtThe text was updated successfully, but these errors were encountered: