You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GetAsyncStateMachineDescription may change behavior on app processed by ILLink #32921
If a field is not accessed by anything in the application directly, the linker will remove it from the type (with exceptions to non-auto layout types and some special cases). So the enumeration of all fields on a type may return less fields when the app is processed with the linker.
Please review this and determine if the behavior is acceptable or if we should try to find a solution such that we would guarantee that all fields are preserved in this case.
Please review this and determine if the behavior is acceptable or if we should try to find a solution such that we would guarantee that all fields are preserved in this case.
It's acceptable. This is used to get a description of the state of the state machine when an async method doesn't complete / hangs and gets GC'd in that state; we output an EventSource event to help the dev track down their bug, and we include in it the state of the state machine as best we can gather it. It's best effort, and if there's something on the state machine that's never touched such that the linker removes it, it's also not going to be meaningful in tracking down the actual problem.
As an aside, is the linker actually able to remove fields from async state machines? That surprises me. I would have expected anything the linker could possibly remove wouldn't have been promoted from locals to fields in the first place by Roslyn.
You're probably right - I didn't actually try to see if there's a counter example.
I based the description above on analyzing the code looking for reflection calls which may provide different results on trimmed assemblies. Unless I'm pretty certain I'm trying to avoid definitive statements about the code's behavior as I don't understand the affected area that well.
// If the state machine is being finalized, something went wrong during its processing,
// e.g. it awaited something that got collected without itself having been completed.
// Fire an event with details about the state machine to help with debugging.
if(!IsCompleted)// double-check it's not completed, just to help minimize false positives
{
TplEventSource.Log.IncompleteAsyncMethod(this);
}
}
And the points that:
Fields on the async state machine shouldn't be able to be trimmed.
Even if they are trimmed, this won't affect the runtime of an application. Those fields just won't be written to the EventSource. If the fields were trimmed away, this seems totally reasonable.
Thanks a lot for the confirmation. Can we please keep this open a bit longer - we're currently figuring out the best way to tell the tooling that it should not warn about some code.
we're currently figuring out the best way to tell the tooling that it should not warn about some code.
There are now multiple issues in the same state, right? This, the delegate one, etc. Seems like they should all be closed in favor of an issue specifically about annotating all such methods, rather than multiple issues tracking e same thing. Up to you, though.
Activity
vitek-karas commentedon Feb 27, 2020
@eerhardt
stephentoub commentedon Feb 27, 2020
It's acceptable. This is used to get a description of the state of the state machine when an async method doesn't complete / hangs and gets GC'd in that state; we output an EventSource event to help the dev track down their bug, and we include in it the state of the state machine as best we can gather it. It's best effort, and if there's something on the state machine that's never touched such that the linker removes it, it's also not going to be meaningful in tracking down the actual problem.
stephentoub commentedon Feb 27, 2020
As an aside, is the linker actually able to remove fields from async state machines? That surprises me. I would have expected anything the linker could possibly remove wouldn't have been promoted from locals to fields in the first place by Roslyn.
vitek-karas commentedon Feb 27, 2020
You're probably right - I didn't actually try to see if there's a counter example.
I based the description above on analyzing the code looking for reflection calls which may provide different results on trimmed assemblies. Unless I'm pretty certain I'm trying to avoid definitive statements about the code's behavior as I don't understand the affected area that well.
eerhardt commentedon Mar 12, 2020
I think we can close this issue, right? From @stephentoub's analysis above, the only usage of this method is:
runtime/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs
Lines 262 to 271 in 84cf6a1
And the points that:
stephentoub commentedon Mar 12, 2020
Yup. The only question is if we need to attribute the method in some way to keep it off tooling radar in the future, and if so, how.
vitek-karas commentedon Mar 13, 2020
Thanks a lot for the confirmation. Can we please keep this open a bit longer - we're currently figuring out the best way to tell the tooling that it should not warn about some code.
stephentoub commentedon Mar 13, 2020
There are now multiple issues in the same state, right? This, the delegate one, etc. Seems like they should all be closed in favor of an issue specifically about annotating all such methods, rather than multiple issues tracking e same thing. Up to you, though.
vitek-karas commentedon Mar 13, 2020
The delegate issue is somewhat different.
Is it a problem to have several issues opened as a way to track this work?