Affects: \Spring-WebFlux 5.1.9:RELEASE
Hello,
I catch this error often on Debian 9 and very rarely on Windows 10 (OpenJDK 12.0.2+10).
I do this:
1. Create very long WebClient responses chain;
2. Subscribe to the Publisher and set the Disposable to a member value of Configuration class;
3. In onComplete i can publish a special async (For ex: SpecEvent) event to Configuration;
4. (AsyncEventListener) In SpecEventHandler i invoke dispose(), sleep one second and close current ApplicationContext;
5. And I get such error:
[17:56:07][Step 1/1] java.lang.IllegalStateException: java.lang.IllegalStateException: Socket couldn't be stopped within 3000ms
[17:56:07][Step 1/1] at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext$ServerManager.stop(ReactiveWebServerApplicationContext.java:233)
[17:56:07][Step 1/1] at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.stopAndReleaseReactiveWebServer(ReactiveWebServerApplicationContext.java:157)
[17:56:07][Step 1/1] at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onClose(ReactiveWebServerApplicationContext.java:151)
[17:56:07][Step 1/1] at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1032)
[17:56:07][Step 1/1] at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:975)
[17:56:07][Step 1/1] at com.myexample.external.pendingResolver.PendingResolver.handleStopEvent(PendingResolver.java:112) // My async handler
[17:56:07][Step 1/1] at com.myexample.external.pendingResolver.PendingResolver$$FastClassBySpringCGLIB$$2fb70d9d.invoke(<generated>)
[17:56:07][Step 1/1] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
[17:56:07][Step 1/1] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
[17:56:07][Step 1/1] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
[17:56:07][Step 1/1] at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115)
[17:56:07][Step 1/1] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[17:56:07][Step 1/1] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[17:56:07][Step 1/1] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[17:56:07][Step 1/1] at java.base/java.lang.Thread.run(Thread.java:835)
[17:56:07][Step 1/1] Caused by: java.lang.IllegalStateException: Socket couldn't be stopped within 3000ms
[17:56:07][Step 1/1] at reactor.netty.DisposableChannel.disposeNow(DisposableChannel.java:98)
[17:56:07][Step 1/1] at reactor.netty.DisposableChannel.disposeNow(DisposableChannel.java:82)
[17:56:07][Step 1/1] at org.springframework.boot.web.embedded.netty.NettyWebServer.stop(NettyWebServer.java:120)
[17:56:07][Step 1/1] at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext$ServerManager.stop(ReactiveWebServerApplicationContext.java:230)
[17:56:07][Step 1/1] ... 14 common frames omitted
[17:56:07][Step 1/1] Process exited with code 0
I can increase my sleep time, and the error will appear less.
Also i found the similar issue.
Comment From: Bittuw
I found the issue. In Configuration i also receive ContextCloseEvent and in this async handler was also called dispose of the same Disposable. I thought that dispose is thread-safe. I was wrong. But i didn't find the explanation of the difference in behavior on different platforms...