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.

reactive @Transactional fails with java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking

See original GitHub issue

From #1524.

The underlying issue is that TransactionInterceptor is being called instead of CouchbaseTransactionInterceptor. And it should be calling executeReactive() instead of execute().

@Service
class ScheduleService(
    private val reactiveOperations: ReactiveCouchbaseOperations
) {
    @Transactional
    fun saveScheduleWithTransaction(schedule: Schedule): Mono<Schedule> {
        return reactiveOperations.insertById(Schedule::class.java).one(schedule)
    }
}
java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-3
	at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:83) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
	Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
	*__checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
	*__checkpoint ⇢ HTTP POST "/schedule" [ExceptionHandlingWebHandler]
Original Stack Trace:
		at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:83) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
		at reactor.core.publisher.Mono.block(Mono.java:1675) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
		at org.springframework.data.couchbase.transaction.CouchbaseCallbackTransactionManager.handlePropagation(CouchbaseCallbackTransactionManager.java:191) ~[spring-data-couchbase-5.0.0-M5.jar:5.0.0-M5]
		at org.springframework.data.couchbase.transaction.CouchbaseCallbackTransactionManager.execute(CouchbaseCallbackTransactionManager.java:76) ~[spring-data-couchbase-5.0.0-M5.jar:5.0.0-M5]
		at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:417) ~[spring-tx-6.0.0-M5.jar:6.0.0-M5]
		at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) ~[spring-tx-6.0.0-M5.jar:6.0.0-M5]
		at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.0.0-M5.jar:6.0.0-M5]
		at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-6.0.0-M5.jar:6.0.0-M5]
		at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-6.0.0-M5.jar:6.0.0-M5]
		at com.rbleuse.spring.reactive.couchbase.service.ScheduleService$$EnhancerBySpringCGLIB$$f091fb23.saveScheduleWithTransaction(<generated>) ~[main/:na]
		at com.rbleuse.spring.reactive.couchbase.handler.ScheduleHandler.createSchedule(ScheduleHandler.kt:20) ~[main/:na]

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mikereichecommented, Aug 4, 2022
 		at org.springframework.data.couchbase.transaction.CouchbaseCallbackTransactionManager.handlePropagation(CouchbaseCallbackTransactionManager.java:191) ~[spring-data-couchbase-5.0.0-M5.jar:5.0.0-M5]
		at org.springframework.data.couchbase.transaction.CouchbaseCallbackTransactionManager.lambda$executeReactive$0(CouchbaseCallbackTransactionManager.java:91) ~[spring-data-couchbase-5.0.0-M5.jar:5.0.0-M5]

Ok - I can fix this.

0reactions
rbleusecommented, Aug 6, 2022

Sorry for the issues with block(). We do the testing in java as below, and it’s not in a non-blocking thread.

@GetMapping("/hello")
public Mono<ResponseEntity<String>> hello(@RequestParam(value = "name", defaultValue = "World") String name) {
	return Mono
			.just(new ResponseEntity<>(userService.insertReactive().block().toString(), HttpStatusCode.valueOf(200)));
}

I didn’t notice earlier, but may I know why there’s a block when we want a Mono as result in this endpoint ? Doesn’t it work with a non blocking process ? Something like (didn’t try)

@GetMapping("/hello")
public Mono<ResponseEntity<String>> hello(@RequestParam(value = "name", defaultValue = "World") String name) {
       return userService.insertReactive().map(value -> new ResponseEntity<>(value.toString(), HttpStatusCode.valueOf(200)));
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

block()/blockFirst()/blockLast() are blocking error when calling ...
I think my issue is that I cannot call block() twice in the same function chain. My code snippet is like so: webClient.post()...
Read more >
WebClient.block throws java.lang.IllegalStateException: block ...
block throws java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread #22919.
Read more >
spring-projects/spring-boot - Gitter
Caused by: java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-3.
Read more >
block()/blockFirst()/blockLast() are blocking, which is not ...
[Solved]-block()/blockFirst()/blockLast() are blocking, which is not supported in thread ... The reactive approach is used in non-blocking applications.
Read more >
Flux (reactor-core 3.5.0)
Note that using state in the java.util.function / lambdas used within Flux ... Transform this Flux into a lazy Iterable blocking on Iterator.next()...
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