question

ClaudioResende-8132 avatar image
2 Votes"
ClaudioResende-8132 asked ClaudioResende-8132 edited

cosmos db error while createContainerIfNotExists

I am using azure cosmos db and all of the sudden, it stopped working with the error bellow

Method called:

cosmosDatabase.createContainerIfNotExists(containerProperties);


java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread parallel-10
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:83) ~[reactor-core-3.4.5.jar:3.4.5]
at reactor.core.publisher.Mono.block(Mono.java:1703) ~[reactor-core-3.4.5.jar:3.4.5]
at com.azure.cosmos.CosmosDatabase.blockContainerResponse(CosmosDatabase.java:288) ~[azure-cosmos-4.14.0.jar:na]
at com.azure.cosmos.CosmosDatabase.createContainerIfNotExists(CosmosDatabase.java:195) ~[azure-cosmos-4.14.0.jar:na]



method called save()

java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread parallel-12
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:83) ~[reactor-core-3.4.5.jar:3.4.5]
at reactor.core.publisher.Mono.block(Mono.java:1703) ~[reactor-core-3.4.5.jar:3.4.5]
at com.azure.cosmos.CosmosContainer.blockItemResponse(CosmosContainer.java:235) ~[azure-cosmos-4.14.0.jar:na]
at com.azure.cosmos.CosmosContainer.createItem(CosmosContainer.java:156) ~[azure-cosmos-4.14.0.jar:na]
at service.save(CosmosRepositoryImpl.java:33) ~[classes/:


notice that I am not using Async database.

A bit more of context:

it is is being processed inside a stream where I get a Flux object and iterate over it, and the



<dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>azure-spring-boot-starter-cosmos</artifactId>
            <version>3.4.0</version>
        </dependency>




A react controller call the bellow methods. P.S notice that I changed the names business-related.
````
Service class:

 public Mono<ResponseObect> myMethod(final RequestObject request) {
     return getSomeFlux(request).flatMap(someObject -> {
                RepositoryClass.save(someObject);
                 return Flux.just(someObject);
             }
     ).count().map(ResponseObect::new);

 }

Repo Class:

 public void save(final MyObject newItem, final String containerName) {
     CosmosContainer container = getContainer(containerName);
     CosmosItemResponse<MyObject> savedItem = container.createItem(newItem);

     if (savedItem.getStatusCode() != 201) {
                 do logging
     }
 }

 private CosmosContainer getContainer(final String containerName) {
     CosmosUtils.createContainerIfNotExists(containerName, cosmosDatabase);
     return cosmosDatabase.getContainer(containerName);
 }

```

azure-cosmos-db
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @claudioresende-8132,
Which SDK version you are using ? Are you using .block() ? Can you please share your code snippet for reference ?

Thanks
Saurabh

0 Votes 0 ·

Hi Saurabh, thank you for interaction, I updated the question with a bit more of details

0 Votes 0 ·

Investigating a bit deeper Cosmos db api, it is using block, even though I am not using the Async database.
I don't like the idea of using reactive methods when I choose the no Async client, database, container....
But what I did that solved the problem was replacing my objects with async ones.

But some weird behavior happens, my Consumer(the one I am passing to subscribe(consumer)) is only getting executed when the container already exists, otherwise, it is not even though the container is being created.

cosmosContainerResponseMono.subscribe(containerResponse -> {
            if (containerResponse.getStatusCode() == 200) {
                log.info("Container created: [{}] ", containerName);
                containerCreated.set(true);
            }
        });


And also it is strange to me why it was working before and all of the sudden it has stopped

0 Votes 0 ·

Hi @claudioresende-8132,

Thanks for sharing the information. I am checking internally on the same and get back to you.

Thanks
Saurabh

0 Votes 0 ·

Hi @claudioresende-8132,

Sorry for the delay on this. I am still waiting for products team response on this issue and update you on as soon as I hear back.

Thanks
Saurabh

0 Votes 0 ·

0 Answers