Skip to content

GetAsyncStateMachineDescription may change behavior on app processed by ILLink #32921

Closed

Description

@vitek-karas

The code in AsyncMethodBuilderCore.GetAsyncStateMachineDescription enumerates all fields on the state machine type and prints out their values into the resulting string.

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.

Activity

  1. added
    linkable-framework
    on Feb 27, 2020
  2. added
    untriaged
    on Feb 27, 2020
  3. vitek-karas commented on Feb 27, 2020

    @vitek-karas
    MemberAuthor
  4. stephentoub commented on Feb 27, 2020

    @stephentoub
    Member

    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.

  5. stephentoub commented on Feb 27, 2020

    @stephentoub
    Member

    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.

  6. vitek-karas commented on Feb 27, 2020

    @vitek-karas
    MemberAuthor

    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.

  7. eerhardt commented on Mar 12, 2020

    @eerhardt
    Member

    I think we can close this issue, right? From @stephentoub's analysis above, the only usage of this method is:

    ~DebugFinalizableAsyncStateMachineBox()
    {
    // 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:

    1. Fields on the async state machine shouldn't be able to be trimmed.
    2. 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.
  8. stephentoub commented on Mar 12, 2020

    @stephentoub
    Member

    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.

  9. vitek-karas commented on Mar 13, 2020

    @vitek-karas
    MemberAuthor

    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.

  10. stephentoub commented on Mar 13, 2020

    @stephentoub
    Member

    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.

  11. vitek-karas commented on Mar 13, 2020

    @vitek-karas
    MemberAuthor

    The delegate issue is somewhat different.
    Is it a problem to have several issues opened as a way to track this work?

  12. ghost locked as resolved and limited conversation to collaborators on Dec 10, 2020
  13. removed
    untriaged
    on Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Runtimelinkable-framework

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions