java.lang.IllegalStateException: It is invalid to call isReady() when the response has not been put into non-blocking mode

Spring JIRA | Jose Antonio Iñigo | 7 months ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    I have noticed a different behaviour between Spring 4's controllers with SseEmitter and Spring 5's controllers with Flux producing "text/event-stream". In *Spring 4*, calling the stream from a browser it will run forever: {code:java} @RequestMapping("/accounts/alerts") public SseEmitter getAccountAlertsNoPathVariable(HttpSession session) { SseEmitter emitter = new SseEmitter(Long.MAX_VALUE); Thread t1 = new Thread(() ->{ try { int i = 0; while(++i<=10000){ Thread.sleep(1000); System.out.println("Sending"); try{ emitter.send(new Alert((long)i, "Alert message"+i)); }catch(ClientAbortException cae){ cae.printStackTrace(); i = 10000; } } emitter.complete(); } catch (IOException | InterruptedException e) { e.printStackTrace(); } }); t1.start(); return emitter; } } {code} However in *Spring 5*'s web reactive it crashes after reaching the (tomcat 8) container's request timeout (30 seconds): {code:java} @GetMapping(value="/accounts/{id}/alerts/live", produces="text/event-stream") public Flux<Alert> getAccountAlertsStreaming(@PathVariable Integer id) { return accountService.getAccountAlertsStreaming(id); } ... public Flux<Alert> getAccountAlertsStreaming(Integer id){ return Flux.range(1, 50) .map((Integer i) -> { return new Alert((long)i, "Alert message"+i); }) .delayMillis(1000) .log(); } {code} *Exception:* {code:java} 2016-10-03 10:04:45.908 INFO 4588 --- [ timer-1] reactor.Flux.ConcatMap.2 : request(1) 2016-10-03 10:04:46.910 INFO 4588 --- [ timer-1] reactor.Flux.ConcatMap.2 : onNext(Alert [alertId=31, message=Alert message31]) 2016-10-03 10:04:46.912 INFO 4588 --- [ timer-1] reactor.Flux.ConcatMap.2 : cancel() 2016-10-03 10:04:46.922 DEBUG 4588 --- [ timer-1] o.s.w.s.h.ExceptionHandlingWebHandler : Could not complete request java.lang.IllegalStateException: It is invalid to call isReady() when the response has not been put into non-blocking mode at org.apache.coyote.Response.isReady(Response.java:616) ~[tomcat-embed-core-8.5.5.jar:8.5.5] at org.apache.catalina.connector.OutputBuffer.isReady(OutputBuffer.java:677) ~[tomcat-embed-core-8.5.5.jar:8.5.5] at org.apache.catalina.connector.CoyoteOutputStream.isReady(CoyoteOutputStream.java:155) ~[tomcat-embed-core-8.5.5.jar:8.5.5] at org.springframework.http.server.reactive.ServletServerHttpResponse$ResponseBodyProcessor.isWritePossible(ServletServerHttpResponse.java:168) ~[spring-web-5.0.0.M2.jar:5.0.0.M2] at org.springframework.http.server.reactive.AbstractResponseBodyProcessor.writeIfPossible(AbstractResponseBodyProcessor.java:142) ~[spring-web-5.0.0.M2.jar:5.0.0.M2] at org.springframework.http.server.reactive.AbstractResponseBodyProcessor.access$300(AbstractResponseBodyProcessor.java:47) ~[spring-web-5.0.0.M2.jar:5.0.0.M2] at org.springframework.http.server.reactive.AbstractResponseBodyProcessor$State$2.onNext(AbstractResponseBodyProcessor.java:223) ~[spring-web-5.0.0.M2.jar:5.0.0.M2] at org.springframework.http.server.reactive.AbstractResponseBodyProcessor.onNext(AbstractResponseBodyProcessor.java:77) ~[spring-web-5.0.0.M2.jar:5.0.0.M2] at org.springframework.http.server.reactive.AbstractResponseBodyProcessor.onNext(AbstractResponseBodyProcessor.java:47) ~[spring-web-5.0.0.M2.jar:5.0.0.M2] at reactor.core.publisher.FluxConcatArray$ConcatArraySubscriber.onNext(FluxConcatArray.java:162) ~[reactor-core-3.0.2.RELEASE.jar:na] at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:1508) ~[reactor-core-3.0.2.RELEASE.jar:na] at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.set(Operators.java:1225) ~[reactor-core-3.0.2.RELEASE.jar:na] at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onSubscribe(Operators.java:1188) ~[reactor-core-3.0.2.RELEASE.jar:na] at reactor.core.publisher.MonoJust.subscribe(MonoJust.java:55) ~[reactor-core-3.0.2.RELEASE.jar:na] at reactor.core.publisher.FluxConcatArray$ConcatArraySubscriber.onComplete(FluxConcatArray.java:193) ~[reactor-core-3.0.2.RELEASE.jar:na] at reactor.core.publisher.FluxConcatArray.subscribe(FluxConcatArray.java:96) ~[reactor-core-3.0.2.RELEASE.jar:na] at org.springframework.http.server.reactive.AbstractResponseBodyFlushProcessor$State$2.onNext(AbstractResponseBodyFlushProcessor.java:150) ~[spring-web-5.0.0.M2.jar:5.0.0.M2] at org.springframework.http.server.reactive.AbstractResponseBodyFlushProcessor.onNext(AbstractResponseBodyFlushProcessor.java:72) ~[spring-web-5.0.0.M2.jar:5.0.0.M2] at org.springframework.http.server.reactive.AbstractResponseBodyFlushProcessor.onNext(AbstractResponseBodyFlushProcessor.java:44) ~[spring-web-5.0.0.M2.jar:5.0.0.M2] at org.springframework.http.server.reactive.ChannelSendOperator$WriteWithBarrier.doNext(ChannelSendOperator.java:95) ~[spring-web-5.0.0.M2.jar:5.0.0.M2] at reactor.core.publisher.Operators$SubscriberAdapter.onNext(Operators.java:1021) ~[reactor-core-3.0.2.RELEASE.jar:na] at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:122) [reactor-core-3.0.2.RELEASE.jar:na] at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:122) [reactor-core-3.0.2.RELEASE.jar:na] at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:168) [reactor-core-3.0.2.RELEASE.jar:na] at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.innerNext(FluxConcatMap.java:261) [reactor-core-3.0.2.RELEASE.jar:na] at reactor.core.publisher.FluxConcatMap$ConcatMapInner.onNext(FluxConcatMap.java:743) [reactor-core-3.0.2.RELEASE.jar:na] at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:122) [reactor-core-3.0.2.RELEASE.jar:na] at reactor.core.publisher.MonoDelay$MonoDelayRunnable.run(MonoDelay.java:88) [reactor-core-3.0.2.RELEASE.jar:na] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:522) [na:1.8.0-internal] at java.util.concurrent.FutureTask.run(FutureTask.java:277) [na:1.8.0-internal] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:191) [na:1.8.0-internal] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [na:1.8.0-internal] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153) [na:1.8.0-internal] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [na:1.8.0-internal] at java.lang.Thread.run(Thread.java:785) [na:1.8.0-internal] 2016-10-03 10:04:46.923 DEBUG 4588 --- [ timer-1] o.s.h.s.r.ServletServerHttpResponse : Can't set the status 500 because the HTTP response has already been committed 2016-10-03 10:04:46.923 DEBUG 4588 --- [ timer-1] o.s.h.s.r.ServletHttpHandlerAdapter : Successfully completed request {code}

    Spring JIRA | 7 months ago | Jose Antonio Iñigo
    java.lang.IllegalStateException: It is invalid to call isReady() when the response has not been put into non-blocking mode
  2. 0

    Cannot display my pdf in my webApplication (not in blocking mode)

    Stack Overflow | 1 year ago | yeddez
    java.lang.IllegalStateException: not in non blocking mode.
  3. 0

    Buffer error while sending file using AsyncContext

    Stack Overflow | 1 year ago | user2959589
    java.lang.IllegalStateException: not in non blocking mode.
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    How can I cope with "IllegalStateException: BeanFactory not initialized or already closed"?

    Stack Overflow | 6 years ago | user569825
    java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
  6. 0

    issues in spring petclinic applicaiton

    Stack Overflow | 4 years ago | user2216702
    java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - c all 'refresh' before multicasting events via the context: Root WebApplicationCon text: startup date [Wed Mar 27 11:31:56 CDT 2013]; root of context hierarchy at org.springframework.context.support.AbstractApplic ationContext.getApp licationEventMulticaster(AbstractApplicationContex t.java:347) [spring-context-3. 2.2.RELEASE.jar:3.2.2.RELEASE] at org.springframework.context.support.AbstractApplic ationContext.publis hEvent(AbstractApplicationContext.java:334) [spring-context-3.2.2.RELEASE.jar:3. 2.2.RELEASE] at org.springframework.context.support.AbstractApplic ationContext.doClos e(AbstractApplicationContext.java:1049) [spring-context-3.2.2.RELEASE.jar:3.2.2. RELEASE] at org.springframework.context.support.AbstractApplic ationContext.close( AbstractApplicationContext.java:1010) [spring-context-3.2.2.RELEASE.jar:3.2.2.RE LEASE] at org.springframework.web.context.ContextLoader.clos eWebApplicationCont ext(ContextLoader.java:558) [spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE] at org.springframework.web.context.ContextLoaderListe ner.contextDestroye d(ContextLoaderListener.java:143) [spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE] at org.apache.catalina.core.StandardContext.listenerS top(StandardContext .java:4831) [tomcat-embed-core-7.0.30.jar:7.0.30] at org.apache.catalina.core.StandardContext.stopInter nal(StandardContext .java:5478) [tomcat-embed-core-7.0.30.jar:7.0.30] at org.apache.catalina.util.LifecycleBase.stop(Lifecy cleBase.java:232) [ tomcat-embed-core-7.0.30.jar:7.0.30] at org.apache.catalina.util.LifecycleBase.start(Lifec ycleBase.java:160) [tomcat-embed-core-7.0.30.jar:7.0.30] at org.apache.catalina.core.ContainerBase$StartChild. call(ContainerBase. java:1559) [tomcat-embed-core-7.0.30.jar:7.0.30] at org.apache.catalina.core.ContainerBase$StartChild. call(ContainerBase. java:1549) [tomcat-embed-core-7.0.30.jar:7.0.30] at java.util.concurrent.FutureTask$Sync.innerRun(Futu reTask.java:303) [n a:1.6.0_20] at java.util.concurrent.FutureTask.run(FutureTask.jav a:138) [na:1.6.0_20 ] at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExec utor.java:886) [na:1.6.0_20] at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor .java:908) [na:1.6.0_20]

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalStateException

      It is invalid to call isReady() when the response has not been put into non-blocking mode

      at org.apache.coyote.Response.isReady()
    2. Grizzly HTTP
      Response.isReady
      1. org.apache.coyote.Response.isReady(Response.java:616)[tomcat-embed-core-8.5.5.jar:8.5.5]
      1 frame
    3. Glassfish Core
      CoyoteOutputStream.isReady
      1. org.apache.catalina.connector.OutputBuffer.isReady(OutputBuffer.java:677)[tomcat-embed-core-8.5.5.jar:8.5.5]
      2. org.apache.catalina.connector.CoyoteOutputStream.isReady(CoyoteOutputStream.java:155)[tomcat-embed-core-8.5.5.jar:8.5.5]
      2 frames
    4. org.springframework.http
      AbstractResponseBodyProcessor.onNext
      1. org.springframework.http.server.reactive.ServletServerHttpResponse$ResponseBodyProcessor.isWritePossible(ServletServerHttpResponse.java:168)[spring-web-5.0.0.M2.jar:5.0.0.M2]
      2. org.springframework.http.server.reactive.AbstractResponseBodyProcessor.writeIfPossible(AbstractResponseBodyProcessor.java:142)[spring-web-5.0.0.M2.jar:5.0.0.M2]
      3. org.springframework.http.server.reactive.AbstractResponseBodyProcessor.access$300(AbstractResponseBodyProcessor.java:47)[spring-web-5.0.0.M2.jar:5.0.0.M2]
      4. org.springframework.http.server.reactive.AbstractResponseBodyProcessor$State$2.onNext(AbstractResponseBodyProcessor.java:223)[spring-web-5.0.0.M2.jar:5.0.0.M2]
      5. org.springframework.http.server.reactive.AbstractResponseBodyProcessor.onNext(AbstractResponseBodyProcessor.java:77)[spring-web-5.0.0.M2.jar:5.0.0.M2]
      6. org.springframework.http.server.reactive.AbstractResponseBodyProcessor.onNext(AbstractResponseBodyProcessor.java:47)[spring-web-5.0.0.M2.jar:5.0.0.M2]
      6 frames
    5. reactor.core.publisher
      FluxConcatArray.subscribe
      1. reactor.core.publisher.FluxConcatArray$ConcatArraySubscriber.onNext(FluxConcatArray.java:162)[reactor-core-3.0.2.RELEASE.jar:na]
      2. reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:1508)[reactor-core-3.0.2.RELEASE.jar:na]
      3. reactor.core.publisher.Operators$MultiSubscriptionSubscriber.set(Operators.java:1225)[reactor-core-3.0.2.RELEASE.jar:na]
      4. reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onSubscribe(Operators.java:1188)[reactor-core-3.0.2.RELEASE.jar:na]
      5. reactor.core.publisher.MonoJust.subscribe(MonoJust.java:55)[reactor-core-3.0.2.RELEASE.jar:na]
      6. reactor.core.publisher.FluxConcatArray$ConcatArraySubscriber.onComplete(FluxConcatArray.java:193)[reactor-core-3.0.2.RELEASE.jar:na]
      7. reactor.core.publisher.FluxConcatArray.subscribe(FluxConcatArray.java:96)[reactor-core-3.0.2.RELEASE.jar:na]
      7 frames
    6. org.springframework.http
      ChannelSendOperator$WriteWithBarrier.doNext
      1. org.springframework.http.server.reactive.AbstractResponseBodyFlushProcessor$State$2.onNext(AbstractResponseBodyFlushProcessor.java:150)[spring-web-5.0.0.M2.jar:5.0.0.M2]
      2. org.springframework.http.server.reactive.AbstractResponseBodyFlushProcessor.onNext(AbstractResponseBodyFlushProcessor.java:72)[spring-web-5.0.0.M2.jar:5.0.0.M2]
      3. org.springframework.http.server.reactive.AbstractResponseBodyFlushProcessor.onNext(AbstractResponseBodyFlushProcessor.java:44)[spring-web-5.0.0.M2.jar:5.0.0.M2]
      4. org.springframework.http.server.reactive.ChannelSendOperator$WriteWithBarrier.doNext(ChannelSendOperator.java:95)[spring-web-5.0.0.M2.jar:5.0.0.M2]
      4 frames
    7. reactor.core.publisher
      MonoDelay$MonoDelayRunnable.run
      1. reactor.core.publisher.Operators$SubscriberAdapter.onNext(Operators.java:1021)[reactor-core-3.0.2.RELEASE.jar:na]
      2. reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:122)[reactor-core-3.0.2.RELEASE.jar:na]
      3. reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:122)[reactor-core-3.0.2.RELEASE.jar:na]
      4. reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:168)[reactor-core-3.0.2.RELEASE.jar:na]
      5. reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.innerNext(FluxConcatMap.java:261)[reactor-core-3.0.2.RELEASE.jar:na]
      6. reactor.core.publisher.FluxConcatMap$ConcatMapInner.onNext(FluxConcatMap.java:743)[reactor-core-3.0.2.RELEASE.jar:na]
      7. reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:122)[reactor-core-3.0.2.RELEASE.jar:na]
      8. reactor.core.publisher.MonoDelay$MonoDelayRunnable.run(MonoDelay.java:88)[reactor-core-3.0.2.RELEASE.jar:na]
      8 frames
    8. Java RT
      Thread.run
      1. java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:522)[na:1.8.0-internal]
      2. java.util.concurrent.FutureTask.run(FutureTask.java:277)[na:1.8.0-internal]
      3. java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:191)[na:1.8.0-internal]
      4. java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)[na:1.8.0-internal]
      5. java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153)[na:1.8.0-internal]
      6. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)[na:1.8.0-internal]
      7. java.lang.Thread.run(Thread.java:785)[na:1.8.0-internal]
      7 frames