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 | 5 months ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  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 | 5 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 | 11 months ago | yeddez
    java.lang.IllegalStateException: not in non blocking mode.
  3. 0

    Buffer error while sending file using AsyncContext

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

    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