Skip to content
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

Deadlock in Blazor WASM + CosmoClient that happens in .net7 but not .net6 #79704

Open
1 task done
y2kbugger opened this issue Dec 14, 2022 · 26 comments
Open
1 task done
Assignees
Labels
arch-wasm WebAssembly architecture area-VM-meta-mono needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Milestone

Comments

@y2kbugger
Copy link

y2kbugger commented Dec 14, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

See: Azure/azure-cosmos-dotnet-v3#3599

When newing up a CosmosClient (either as DI services or in async callback on a page) the entire browser tab will deadlock.

This does not occur when I retarget the app to .net6

The CosmosSDK would like to help, but I lack the knowledge of how to pinpoint the deadlock since Blazor WASM doesnt appear to have profiling.

Expected Behavior

No deadlock

Steps To Reproduce

https://github.com/y2kbugger/ReproduceDeadlockIssueBlazorWasmNet7

Goto the counter page and put in the key

TxzSgDHnH3yz8WsQ0bdoElUPgrPz98Bk0OCGTMG70fEz77dAeCLEVjKmqW71JIgEVvqrN0be4RtQACDbiZyfLQ==

and click the button.

Notice that it makes it past the final print statement before deadlocking.

Exceptions (if any)

No response

.NET Version

7.0.100

Anything else?

No response

@javiercn javiercn transferred this issue from dotnet/aspnetcore Dec 15, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Dec 15, 2022
@javiercn
Copy link
Member

@lewing @thaystg any idea on how to best approach this?

@thaystg
Copy link
Member

thaystg commented Dec 15, 2022

@y2kbugger does it happen also if you are not debugging?

@y2kbugger
Copy link
Author

@thaystg if dotnet run is "debugging enabled" is there a way to run a production release locally?

I've tried configuring as "Production"
image

and it shows it took in the terminal:
image

But in the console it is still seems like debugging is enable when I look at the developer console

Debugging hotkey: Shift+Alt+D (when application has focus)

@javiercn
Copy link
Member

@y2kbugger publish your app and run the published output

@thaystg
Copy link
Member

thaystg commented Dec 15, 2022

Oh, okay, for me the question is answered, you are running outside VS, so debugger is not attached. Thanks.

@y2kbugger
Copy link
Author

And just for completeness I served a published app and it still occurs the same way.

@y2kbugger
Copy link
Author

I noticed they have some workarounds for previous deadlock issues that deal occur then there is no debugger attached. https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos/src/CosmosClient.cs#L144
Maybe something changed between net6 and net7 either in runtime or aspnetcore that broke the workaround?

@marek-safar marek-safar added the arch-wasm WebAssembly architecture label Jul 21, 2023
@ghost
Copy link

ghost commented Jul 21, 2023

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

See: Azure/azure-cosmos-dotnet-v3#3599

When newing up a CosmosClient (either as DI services or in async callback on a page) the entire browser tab will deadlock.

This does not occur when I retarget the app to .net6

The CosmosSDK would like to help, but I lack the knowledge of how to pinpoint the deadlock since Blazor WASM doesnt appear to have profiling.

Expected Behavior

No deadlock

Steps To Reproduce

https://github.com/y2kbugger/ReproduceDeadlockIssueBlazorWasmNet7

Goto the counter page and put in the key

TxzSgDHnH3yz8WsQ0bdoElUPgrPz98Bk0OCGTMG70fEz77dAeCLEVjKmqW71JIgEVvqrN0be4RtQACDbiZyfLQ==

and click the button.

Notice that it makes it past the final print statement before deadlocking.

Exceptions (if any)

No response

.NET Version

7.0.100

Anything else?

No response

Author: y2kbugger
Assignees: -
Labels:

arch-wasm, untriaged, area-VM-meta-mono

Milestone: -

@marek-safar marek-safar removed the untriaged New issue has not been triaged by the area owner label Jul 21, 2023
@marek-safar marek-safar added this to the 8.0.0 milestone Jul 21, 2023
@pavelsavara
Copy link
Member

https://throwawaycosmostest1234555asdf.documents.azure.com/ is gone by now. Does the problem still apply to latest net8 preview ?

@pavelsavara pavelsavara added the needs-author-action An issue or pull request that requires more info or actions from the author. label Aug 30, 2023
@ghost
Copy link

ghost commented Aug 30, 2023

This issue has been marked needs-author-action and may be missing some important information.

@ghost ghost added the no-recent-activity label Sep 13, 2023
@ghost
Copy link

ghost commented Sep 13, 2023

This issue has been automatically marked no-recent-activity because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will remove no-recent-activity.

@y2kbugger
Copy link
Author

y2kbugger commented Sep 13, 2023

I've stood up a new cosmos client.
Here is the new key:
QL1cYvWmgVoSKMfwGyKl0Ojro1FwZCpcdpT6cK9cDLzFZJgMVKfVtvfyGr2RtJ6oBk8YkKAzD1cSACDbtGOlTA==

can confirm it still fails with the latest dotnet 7.0.11, but without updating other packages

@ghost ghost added needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration and removed needs-author-action An issue or pull request that requires more info or actions from the author. no-recent-activity labels Sep 13, 2023
@pavelsavara
Copy link
Member

image

@y2kbugger
Copy link
Author

make sure to pull the latest commit.
y2kbugger/ReproduceDeadlockIssueBlazorWasmNet7@f221795

@y2kbugger
Copy link
Author

y2kbugger commented Sep 13, 2023

I've stood up a new cosmos client. Here is the new key: QL1cYvWmgVoSKMfwGyKl0Ojro1FwZCpcdpT6cK9cDLzFZJgMVKfVtvfyGr2RtJ6oBk8YkKAzD1cSACDbtGOlTA==

can confirm it still fails with the latest dotnet 7.0.11, but without updating other packages

Also confirmed that it still locks in:

  • 7.0.11 without updating any packages
  • 7.0.11 after updating to latest WebAssembly 7.0.11 and Cosmos 3.35.3
  • 8.0.0 rc1 after updating to latest WebAssembly 7.0.11 and Cosmos 3.35.3

image

@pavelsavara
Copy link
Member

It's spinning inside of interp, never finished the _schedule_background_exec

image

@pavelsavara
Copy link
Member

That could be user code spinning, but it's hard to tell what.

@y2kbugger
Copy link
Author

Even if you comment out the rest of the example, it prints the "Client Created" and still hangs:

    private async Task IncrementCount()
    {
        Console.WriteLine(RuntimeInformation.FrameworkDescription);
        Console.WriteLine(RuntimeInformation.OSDescription);

        currentCount++;
        Console.WriteLine("Creating client");

        // Create a new client
        var c = new CosmosClient(
            CosmosEndpoint, CosmosKey,
            new CosmosClientOptions()
                {
                    ApplicationName = "Test",
                    ConnectionMode = ConnectionMode.Gateway,
                }
            );
        Console.WriteLine($"Client created: `{c.ToString()}`");
    }

@y2kbugger
Copy link
Author

I wish I knew how to debug in the browser with symbols, but it's too far away from my day job to spend time figuring that out as we have a workaround in place for this. e.g. serverless REST layer.

But according to microsoft, direct access via a browser is a supported use case for Cosmos, and they even have it in their Javascript sdk, so this still should be fixed since it's their spa framework.

Once you set the CORS rules for your Azure Cosmos account, a properly authenticated request made to the service from a browser client will be evaluated to determine whether it is allowed according to the rules you have specified.

https://learn.microsoft.com/en-us/javascript/api/overview/azure/cosmos-readme?view=azure-node-latest

@maraf
Copy link
Member

maraf commented Oct 31, 2023

I wasn't able to figure out yet why it's getting blocked

@maraf maraf modified the milestones: 8.0.0, 9.0.0 Oct 31, 2023
@Avenged
Copy link

Avenged commented Jan 29, 2024

I'm facing the same issue using .NET 8 and Blazor WASM

@pavelsavara
Copy link
Member

Could you please re-compile with <WasmNativeStrip>false</WasmNativeStrip> and share the stack-trace of the deadlock ?

@ilonatommy ilonatommy added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jul 4, 2024
@y2kbugger
Copy link
Author

Could you please re-compile with <WasmNativeStrip>false</WasmNativeStrip> and share the stack-trace of the deadlock ?

sorry I didn't see this. I'll see what I can do tomorrow. I have moved on from .Net stack for new projects but this would be interesting to know. Because we are building enterprise apps, within a private network, monolithic wasm apps would have been great. instead we had to create and host an api which added no value, but was a large complexity burden.

@dotnet-policy-service dotnet-policy-service bot removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Jul 4, 2024
@Avenged
Copy link

Avenged commented Jul 4, 2024

Related to this Azure/azure-cosmos-dotnet-v3#4551

@pavelsavara
Copy link
Member

As I'm thinking about it I realized that native stack trace would be again just stack trace of the Mono interpreter.

Perhaps it would be better to build debug version of the app and stop in there in C# debugger (VS or VS code).
To see what's the managed stack at the time when it's dead-locked.

I wonder if that's some abandoned Task which then never resolves or if that's something spinning busy-loop.
Does the browser UI/DOM respond, does it render ?

Do the JS events tick ? Easy test

setInterval(()=>console.log("UI alive" + new Date().toISOString()),1000);

@maraf maraf modified the milestones: 9.0.0, 10.0.0 Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-VM-meta-mono needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Projects
None yet
Development

No branches or pull requests

9 participants