question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor app with cosmos sdk goes non responsive

See original GitHub issue

We are continuously addressing and improving the SDK, if possible, make sure the problem persist in the latest SDK version.

Describe the bug A clear and concise description of what the bug is.

To Reproduce

  1. Following this url for blazor setup : https://docs.microsoft.com/en-us/aspnet/core/blazor/get-started?view=aspnetcore-3.0&tabs=visual-studio
  2. Create a Blazor Client project
  3. Install nuget package - Install-Package Microsoft.Azure.Cosmos -Version 3.2.0
  4. Run following code snippet in any btn handler click or may be startup var client = new CosmosClient(Endpoint, key);
  5. Blazor app will freeze and ultimately error out.

Expected behavior Should be able to create a cosmos client and then do other operation afterwards

Actual behavior Blazor app will freezes and nothing happens, have stop the debugging session

Environment summary .NET Core SDK (reflecting any global.json): Version: 3.0.100-rc1-014190 Commit: c4d43f672d

Runtime Environment: OS Name: Windows OS Version: 10.0.17134 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.0.100-rc1-014190\

Host (useful for support): Version: 3.0.0-rc1-19456-20 Commit: 8f5d7b1ba4

.NET Core SDKs installed: 2.0.2 [C:\Program Files\dotnet\sdk] 2.1.202 [C:\Program Files\dotnet\sdk] 2.1.502 [C:\Program Files\dotnet\sdk] 2.1.508 [C:\Program Files\dotnet\sdk] 2.1.509 [C:\Program Files\dotnet\sdk] 3.0.100-rc1-014190 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0-rc1.19457.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0-rc1-19456-20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0-rc1-19456-20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Additional context Add any other context about the problem here (for example, complete stack traces or logs).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ealsurcommented, Nov 7, 2019

If you need a service that generates instances of the CosmosClient based on some condition, then create such a service and register it as Singleton during Startup. Our recommendation is that instances should be kept and reused (https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips#sdk-usage).

Even if you wrap the CosmosClient in a using, which will Dispose of the memory, the other problem you have is that connections are not released immediately (https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/), so if you do that many times in a small slice of time, your application might end up consuming a lot of connections (that are still in TIME_WAIT) and depending on where you run the App (some hosting environments have limits to the # of connections), you might face socket starvation.

If creation CosmosClient instances is based on the click of a button, you need to make that process thread-safe and possibly use contention (for example, ConcurrentDictionary or locks), otherwise, bringing your app down is just a matter of a user clicking a button constantly.

1reaction
ealsurcommented, Nov 11, 2019

The approach for a Web API would be the same, I have recently answered a similar question here with some sample code 😄

https://stackoverflow.com/a/58774933/5641598

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blazor WASM Static Web App communicate directly with ...
It seems like communicating directly with cosmos db from the browser would be ideal since it follows the whole faster serverless web approach ......
Read more >
Migrate your application to use the Azure Cosmos DB .NET ...
This article highlights some of the considerations of upgrading your existing .NET application to the newer Azure Cosmos DB .NET SDK v3 for ......
Read more >
CRUD Operations In ASP.NET Core Blazor Server ...
In this article, we will learn how to create the Insert, Update, Delete, and Read operations in an ASP.NET Core Blazor Server App...
Read more >
Blast Off with Blazor: Build a responsive image gallery
In this post, we build a responsive image gallery using Blazor and Tailwind CSS. ... Now, we're going to query Cosmos DB, fetch...
Read more >
Blazor webassembly crud. com/JapSoftwareRock Intro 4 de ...
Blazor webassembly crud. com/JapSoftwareRock Intro 4 de Au The blazor sample uses javascript to copy the table data to local storage for persistence....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found