Comments (7)
thanks @alejojarahi for creating this issue, looks like a genuine problem in case of async client creation. @alzimmermsft I am curious, if this is the same case in azure-core as well and have we solved it? I would like to keep the solutions consistent if possible. Referencing the PR where we added this, will be good to re-iterate our approach to warming up http clients in case of async clients.
azure-core-http-netty doesn't perform a warmup of the Netty HttpClient
from azure-sdk-for-java.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @kushagraThapar @pjohari-ms @TheovanKraay.
from azure-sdk-for-java.
thanks @alejojarahi for creating this issue, looks like a genuine problem in case of async client creation. @alzimmermsft I am curious, if this is the same case in azure-core as well and have we solved it? I would like to keep the solutions consistent if possible. Referencing the PR where we added this, will be good to re-iterate our approach to warming up http clients in case of async clients.
from azure-sdk-for-java.
IMO, we should remove the blocking warmup of the http client.
cc: @xinlian12 / @FabianMeiswinkel
from azure-sdk-for-java.
thanks @alzimmermsft for the confirmation.
@alejojarahi - actually the issue here is not the warmup, rather the way you are creating the cosmos client. The code snippet you pasted in the issue description is creating multiple cosmos clients (per database) which is not recommended. We strongly recommend to only create a singleton client.
azure-cosmos client or any other client if needs to warmup, they will need to call certain APIs that will allow the client to warmup. Ideally, you would want to have a warmed-up client and then only enable the traffic on it (through nio threads or whatever). You would want to warmup the client on the main thread before opening it up for traffic.
If your ask is to make this configurable, we can think about doing so.
from azure-sdk-for-java.
Hi @kushagraThapar. Thanks for the reply.
This error also occurs in the scenario that CosmosAsyncClient is instantiated only onces. Example in Springboot 3
import com.azure.cosmos.CosmosAsyncClient;
import com.azure.cosmos.CosmosClientBuilder;
import reactor.core.publisher.Flux;
public class UserRepository {
private static final String DATABASE_NAME = "test";
CosmosAsyncClient cosmosAsyncClient = null;
public CosmosAsyncClient getInstance() {
if(cosmosAsyncClient == null) {
cosmosAsyncClient = new CosmosClientBuilder()
.endpoint("ENDPOINT")
.key("KEY")
.buildAsyncClient();
}
return cosmosAsyncClient;
}
public Flux<User> getAll() {
return getInstance().getDatabase(DATABASE_NAME)
.getContainer("users")
.queryItems("SELECT * FROM users", User.class);
}
}
17:44:54.516 Data 06-may.-2024 | ERROR | Thread [reactor-http-nio-3] | c.a.c.i.RxDocumentClientImpl | unexpected failure in initializing client.
java.lang.RuntimeException: java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-3
at com.azure.cosmos.implementation.http.ReactorNettyClient.attemptToWarmupHttpClient(ReactorNettyClient.java:116)
at com.azure.cosmos.implementation.http.ReactorNettyClient.createWithConnectionProvider(ReactorNettyClient.java:96)
at com.azure.cosmos.implementation.http.HttpClient.createFixed(HttpClient.java:62)
at com.azure.cosmos.implementation.RxDocumentClientImpl.httpClient(RxDocumentClientImpl.java:744)
at com.azure.cosmos.implementation.RxDocumentClientImpl.<init>(RxDocumentClientImpl.java:508)
at com.azure.cosmos.implementation.RxDocumentClientImpl.<init>(RxDocumentClientImpl.java:335)
at com.azure.cosmos.implementation.RxDocumentClientImpl.<init>(RxDocumentClientImpl.java:295)
at com.azure.cosmos.implementation.AsyncDocumentClient$Builder.build(AsyncDocumentClient.java:275)
at com.azure.cosmos.CosmosAsyncClient.<init>(CosmosAsyncClient.java:170)
at com.azure.cosmos.CosmosClientBuilder.buildAsyncClient(CosmosClientBuilder.java:1084)
at com.azure.cosmos.CosmosClientBuilder.buildAsyncClient(CosmosClientBuilder.java:1071)
at co.com.springexample.entrypoint.UserRepository.getInstance(UserRepository.java:19)
If the reactive client is subject to only being able to start by on the main thread, this can limit or affect the architecture of a project. For example this use case https://stackoverflow.com/questions/73412719/create-recreate-azure-cosmosdb-async-client-from-java-reactor-context.
If the team does not consider it a bug, it should be a configurable functionality
from azure-sdk-for-java.
@alejojarahi the stack overflow code snippet you mentioned is also not a valid use case of the cosmos client, because the customer is trying to create a new cosmos client every time they need to rotate their keys.
SecretAsyncClient secretAsyncClient = new SecretClientBuilder().buildAsyncClient()
...
Mono<CosmosAsyncClient> client = secretAsyncClient.getSecret(KEY_NAME).map(
s -> s.getValue()
).map(
key -> new CosmosClientBuilder()
.endpoint(HOST)
.key(key)
.buildAsyncClient()
);
return client.flatMap(
...
);
Instead they should use a key rotation pattern like some form of KeyCredential
object which has an update()
API to update the key on the fly.
Creating clients randomly and during the execution of the application is never the right approach, as client creation is considered a heavy operation, specially in case of Cosmos SDK where it needs to get Database account, metadata, fill the caches, create TCP / HTTP connections, etc. when the client boots up.
Any application which is doing this on nio thread is basically blocking their I/O resources for unnecessary client creation.
from azure-sdk-for-java.
Related Issues (20)
- UUF - azure-dev-docs-pr - Configure logging in the Azure SDK for Java - Java on Azure | Microsoft Learn HOT 1
- Connection reset by peer HOT 5
- [BUG] RuntimeException when using BlobContainerClient HOT 2
- Checksum verification not working when uploading using stageBlock/commitBlockList or when using blobClient.getBlockBlobClient().getBlobOutputStream HOT 4
- [BUG] 7.16.0 LinkagerError HOT 9
- Azure Identity => ERROR in getToken() call for scopes [https://database.windows.net//.default] HOT 3
- [BUG] NoClassDefFoundError: io/netty/handler/codec/http/HttpDecoderConfig HOT 4
- [BUG] no azure-spring-data-cosmos 3.45.0 find in Maven HOT 2
- Error log from compute client sdk HOT 5
- [QUERY] How to get total count of blobs size in a container? HOT 3
- Azure Identity => ERROR in getToken() call for scopes []: Managed Identity authentication is not available. HOT 4
- [QUERY] How to catch the networking error while use the azure-stream-binder SDK HOT 6
- [BUG] azure-spring-data-cosmos Query Methods always require Criteria inappropriately HOT 4
- [BUG] EventHubConsumerAsyncClient - Connection Aborted HOT 6
- [BUG] StacklessClosedChannelException on Blob Downloads in Windows Azure Functions on Version 12.25.4 HOT 4
- [BUG] Version checking in azure-core-http-netty may encourage users to expose their app to a CVE HOT 4
- [QUERY] Service bus Delivery not on receive link error HOT 2
- ServiceBusMessageSender should refresh maximum message size when service settings change
- Create a BOM for clientcore packages
- [BUG] java sdk with version 2.34.0 throws long running operations error HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-sdk-for-java.