-
Notifications
You must be signed in to change notification settings - Fork 192
reactive @Transactional fails with java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking #1527
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
Comments
I was able to reproduce this. There are a couple issues - one is the call to block() in the non-blocking thread, and the other is that the TransactionInterceptor is used instead of the CouchbaseTransactionInterceptor. If you create a ScheduleService that uses CouchbaseOperations instead of ReactiveOperations, then you will avoid the issue (I realize this isn't the same functionality, but it will let you try out transactions in spring). |
Thanks for your suggestion ! |
I think you might be missing the @EnableTransactionManagement in your configuration class which extends AbstractCouchbaseConfiguration. (If it's in a different class, you might have transaction management, but it won't use the CouchbaseTransactionInterceptor, and the default TransactionInterceptor will attempt to execute reactive transactions as non-reactive transactions.
If you print out the stacktrace in your @transactional method, it should show CouchbaseTransactionInterceptor in the stacktrace.
|
Thanks for investigating. A couple of things : I don't override
And I declared a configuration like this : @Configuration
@EnableTransactionManagement
class CouchbaseConfig {
@Bean(BeanNames.COUCHBASE_TRANSACTION_MANAGER)
fun couchbaseTransactionManager(clientFactory: CouchbaseClientFactory): CouchbaseCallbackTransactionManager {
return CouchbaseCallbackTransactionManager(clientFactory)
}
} This is my set up with current exception. Now I tried to follow your suggestion, I keep same code base but instead declare a config that extends @Configuration
@EnableTransactionManagement
class CouchbaseConfig(
private val properties: CouchbaseProperties
) : AbstractCouchbaseConfiguration() {
override fun getConnectionString(): String {
return properties.connectionString
}
override fun getUserName(): String {
return properties.username
}
override fun getPassword(): String {
return properties.password
}
override fun getBucketName(): String {
return "test"
}
} By doing so, indeed as you mentioned I have to add
Then after adding this configuration properties, the app starts well but I still have the same exception. I can push my code on a dummy repo if you would like to investigate with my configuration |
Thanks for your patience.
I lost track - which exception? The block() exception? Is CouchbaseTransactionInterceptor in the stack trace? |
Yes the blocking exception, a bit different stack trace now but still referring to CouchbaseCallbackTransactionManager.java:191 : stack trace
I'll push my code on a reroducible repo |
Here it is : https://github.com/rbleuse/spring-reactive-couchbase Just run the spring boot app and a curl By the way, saving with a repository (without transaction) doesn't work since 5.0.0-M5 (works fine with M4), I added comments about it, if you want to investigate. |
Ok - I can fix this. |
@rbleuse - this should work now. I tried it on your project. |
@mikereiche indeed now transaction works with latest snapshot ! In my dummy repo there's a second exception that is showcased but was commented. stack trace
Should I create another issue for it ? |
Yes please open an issue.
|
No worries it's milestone/snapshot versions, it's not supposed to be perfect ;) |
I didn't notice earlier, but may I know why there's a block when we want a Mono as result in this endpoint ? @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)));
} |
From #1524.
The underlying issue is that TransactionInterceptor is being called instead of CouchbaseTransactionInterceptor. And it should be calling executeReactive() instead of execute().
The text was updated successfully, but these errors were encountered: