-
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
NativeAOT crash with ConcurrentBag and interfaces #95574
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsDescriptionA NativeAOT app crashes on converting a ConcurrentBag to a ReadOnlyCollection and then to array, when interfaces are involved in generic types. Reproduction Steps
var bag = new System.Collections.Concurrent.ConcurrentBag();
|
This reproes on Windows as well - same as above.
The fail fast is here: runtime/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/CachedInterfaceDispatch.cs Line 47 in b69f79c
|
Workaround is to add something to the bag: var bag = new System.Collections.Concurrent.ConcurrentBag<MyClass>();
+ bag.Add(new()); // empty bag will hit the bug https://github.com/dotnet/runtime/issues/95574
IReadOnlyCollection<IMyInterface> collection = bag;
var array = collection.ToArray(); |
Thanks for trying @am11 but that is not an acceptable workaround because it's a functional change. But I guess it helps to devise one - checking for an empty bag before doing the conversion. |
@vaind, it is definitely a bug (and labeled as such). My comment was mostly from testing perspective that having a non-null item in the bag does not trigger this bug; so the bag has to be empty or with |
Tagging subscribers to 'os-ios': @steveisok, @akoeplinger, @kotlarmilos Issue DetailsDescriptionA NativeAOT app crashes on converting a ConcurrentBag to a ReadOnlyCollection and then to array, when interfaces are involved in generic types. Reproduction Steps
Expected behaviorDon't crash Actual behaviorApp crashes after startup Regression?It works fine without NativeAOT. Known Workaroundsnone Configuration
Other informationNo response
|
Update removing ios label since it repros on Windows, too |
Nice bug! It has been in the product for a while, probably years (we shipped with this in .NET 7 but nobody hit/reported this). The necessary condition to hit this is to not have |
The compiler can generate two kinds of `MethodTable` structures: constructed and unconstructed. The constructed one has a fully populated vtable and GCInfo and is required whenever the object type could be allocated on the heap. The unconstructed one is generated for all other scenarios as a size optimization. We were previously also skipping emission of the interface list in the unconstructed case. But interface list might be required for variant casting. We could introduce yet another `MethodTable` kind for this specific scenario, but it doesn't seem to warrant the complexity. Emitting interface list for all types is a less than 0.1% size regression for the Todos app. It is a 0.5% size regression for Hello World. That part is unfortunate. It's mostly due to the useless numeric interfaces. We can get this size back if we do dotnet#66716 and start trimming interface lists. Fixes dotnet#95574.
* Generate interface lists for necessary EETypes The compiler can generate two kinds of `MethodTable` structures: constructed and unconstructed. The constructed one has a fully populated vtable and GCInfo and is required whenever the object type could be allocated on the heap. The unconstructed one is generated for all other scenarios as a size optimization. We were previously also skipping emission of the interface list in the unconstructed case. But interface list might be required for variant casting. We could introduce yet another `MethodTable` kind for this specific scenario, but it doesn't seem to warrant the complexity. Emitting interface list for all types is a less than 0.1% size regression for the Todos app. It is a 0.5% size regression for Hello World. That part is unfortunate. It's mostly due to the useless numeric interfaces. We can get this size back if we do #66716 and start trimming interface lists. Fixes #95574. * Update NecessaryCanonicalEETypeNode.cs
Description
A NativeAOT app crashes on converting a ConcurrentBag to a ReadOnlyCollection and then to array, when interfaces are involved in generic types.
Reproduction Steps
dotnet new ios
.csproj
to include<PublishAot>true</PublishAot>
FinishedLaunching()
, e.g. just before thereturn true
:Expected behavior
Don't crash
Actual behavior
App crashes after startup
Regression?
It works fine without NativeAOT.
Known Workarounds
none
Configuration
Other information
No response
The text was updated successfully, but these errors were encountered: