Description
Version: Spring Boot 2.2.0.M5
Module: spring-boot-starter-rsocket
When enabling lazy initialization for spring beans (spring.main.lazy-initialization=true
) rSocket components fail to load with the following exception (stack trace abbreviated):
Caused by: java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-2
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:77) ~[reactor-core-3.3.0.BUILD-20190823.142502-144.jar:3.3.0.BUILD-SNAPSHOT]
at reactor.core.publisher.Mono.block(Mono.java:1541) ~[reactor-core-3.3.0.BUILD-20190823.142502-144.jar:3.3.0.BUILD-SNAPSHOT]
at com.arayastudio.quickchat.config.RSocketConfig.rSocket(RSocketConfig.java:30) ~[classes/:na]
at com.arayastudio.quickchat.config.RSocketConfig$$EnhancerBySpringCGLIB$$13ab571d.CGLIB$rSocket$0(<generated>) ~[classes/:na]
at com.arayastudio.quickchat.config.RSocketConfig$$EnhancerBySpringCGLIB$$13ab571d$$FastClassBySpringCGLIB$$5e97efe0.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.2.0.BUILD-20190823.152058-14.jar:5.2.0.BUILD-SNAPSHOT]
This happens specifically when spring-boot-starter-webflux
is also a dependency. What's happening is Spring attempts to load the rSocket components inside of a non-blocking thread when someone hits the app using a webflux-enabled controller. This triggers Schedulers.isInNonBlockingThread()
to return true which throws the exception. Opening this issue at the request of Andy Wilkinson (@wilkinsona) who indicated RSocket components need to be marked as never lazy.
Sample project can be found at https://github.com/ccellist/quickchat-rsocket. Build and run both client and server apps, then try hitting the client with curl -XPOST -H 'Accept: application/json' -H 'Content-Type: application/json' http://localhost:8081/chat -d 'Hello'
to trigger the exception.