Open Korporal opened 8 months ago
I can see a pattern, it actually seems to "hang" the first time it makes calls that invoke an interop Sys.GetUnixRelease. That itself then calls various managed string related functions.
The code transitions from managed, then to the interop native Sys.GetUnixRelease and then that calls back into managed code like Marsha.PtrToString.
That suggests to me that something odd is happening to do with the transition from native back to managed. Here's a different hang, different test app:
That's what the stack looks like after I forcibly break during debug.
Also if I detach the debugger while the code is "hanging" it continues fine, so this is something to do with a debugger being attached, calling into that native layer an doing so inside an async Main function, or perhaps any async function...
This seems to be the code that represents the transition to native:
I measured how long the "hang" lasts and it seems to be consistently 69 seconds or very close to.
This is just FYI:
There is a workaround. Make the async Main
method private and rename it, this is more or less what the C# compiler does too:
public static void Main(string[] args)
{
AsyncMain(args).GetAwaiter().GetResult();
}
private static async Task AsyncMain(string[] args)
{
// Async code can go here
}
This code hangs inside the property getter for
OSVersion
:It behaves the same way when there are additional statements too (including
await
statements). If one runs this under debug and waits for s few seconds, then breaks the code, it is stuck inside the property getter...very very odd.The same code does not exhibit this behavior when run directly on Windows. If you break execution then resume it, it runs fine and terminates, so the act of interrupting it with debug seems to sidestep the issue.
Oh and one more detail, it seems to be the very first statement in the
Main
function, not just thatOSVersion
property. Multipleasync
awaits
in the code seem to work fine too, it is simply the first statement inMain
that gets impacted.A board reset and power restart does not fix this.