java.lang.IllegalStateException: Cannot forward after response has been committed

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • Full Text Bug Listing
    via by Unknown author,
  • When the following code snippet is executed on Tomcat 7.0.59/8.0.20 or Jetty 9.2.9 instead of an error page either nothing (Tomcat) or a "Service Unavailable" (Jetty) page is displayed. Instead of the above behaviour the default (Spring Boot) white-label error page should be handling the faulty request, however fails at: {{org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration.SpelView.render(Map<String, ?>, HttpServletRequest, HttpServletResponse)}} I observed a similar issue: https://github.com/spring-projects/spring-boot/issues/1920 which was fixed in tomcat; however this scenario seems to be Spring Web MVC specific. h3. Sample Source {code} @Controller @EnableAutoConfiguration public class Application { @RequestMapping("/") @ResponseBody DeferredResult<String> home() { DeferredResult<String> result = new DeferredResult<>(2000); ForkJoinPool.commonPool().execute(() -> { doHeavyWork(result); }); return result; } private void doHeavyWork(DeferredResult<String> result) { try { Thread.sleep(3000); } catch (InterruptedException e) { Thread.interrupted(); } result.setResult("Hello World"); } public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); } } {code} h3. Stacktrace Jetty: {code} org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: STREAM at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) at javax.servlet.http.HttpServlet.service(HttpServlet.java:618) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:595) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) at org.eclipse.jetty.server.Server.handleAsync(Server.java:553) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:347) at org.eclipse.jetty.server.HttpChannel.run(HttpChannel.java:261) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.IllegalStateException: STREAM at org.eclipse.jetty.server.Response.getWriter(Response.java:920) at org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$SpelView.render(ErrorMvcAutoConfiguration.java:196) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228) at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) ... 21 common frames omitted {code} h3. Tomcat 8.0.20 {code} java.lang.IllegalStateException: Cannot forward after response has been committed at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:328) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318) at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:439) at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:305) at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:399) at org.apache.catalina.core.AsyncContextImpl.setErrorState(AsyncContextImpl.java:434) at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:289) at org.apache.coyote.http11.AbstractHttp11Processor.asyncDispatch(AbstractHttp11Processor.java:1705) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:650) at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source) {code}
    via by Andreas Kluth,
  • When the following code snippet is executed on Tomcat 7.0.59/8.0.20 or Jetty 9.2.9 instead of an error page either nothing (Tomcat) or a "Service Unavailable" (Jetty) page is displayed. Instead of the above behaviour the default (Spring Boot) white-label error page should be handling the faulty request, however fails at: {{org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration.SpelView.render(Map<String, ?>, HttpServletRequest, HttpServletResponse)}} I observed a similar issue: https://github.com/spring-projects/spring-boot/issues/1920 which was fixed in tomcat; however this scenario seems to be Spring Web MVC specific. h3. Sample Source {code} @Controller @EnableAutoConfiguration public class Application { @RequestMapping("/") @ResponseBody DeferredResult<String> home() { DeferredResult<String> result = new DeferredResult<>(2000); ForkJoinPool.commonPool().execute(() -> { doHeavyWork(result); }); return result; } private void doHeavyWork(DeferredResult<String> result) { try { Thread.sleep(3000); } catch (InterruptedException e) { Thread.interrupted(); } result.setResult("Hello World"); } public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); } } {code} h3. Stacktrace Jetty: {code} org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: STREAM at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) at javax.servlet.http.HttpServlet.service(HttpServlet.java:618) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:595) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) at org.eclipse.jetty.server.Server.handleAsync(Server.java:553) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:347) at org.eclipse.jetty.server.HttpChannel.run(HttpChannel.java:261) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.IllegalStateException: STREAM at org.eclipse.jetty.server.Response.getWriter(Response.java:920) at org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$SpelView.render(ErrorMvcAutoConfiguration.java:196) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228) at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) ... 21 common frames omitted {code} h3. Tomcat 8.0.20 {code} java.lang.IllegalStateException: Cannot forward after response has been committed at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:328) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318) at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:439) at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:305) at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:399) at org.apache.catalina.core.AsyncContextImpl.setErrorState(AsyncContextImpl.java:434) at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:289) at org.apache.coyote.http11.AbstractHttp11Processor.asyncDispatch(AbstractHttp11Processor.java:1705) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:650) at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source) {code}
    via by Andreas Kluth,
    • java.lang.IllegalStateException: Cannot forward after response has been committed at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:321)[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:311)[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:395)[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:254)[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:349)[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.catalina.core.AsyncContextImpl.setErrorState(AsyncContextImpl.java:412)[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:158)[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.coyote.AbstractProcessor.dispatch(AbstractProcessor.java:222)[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:53)[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)[tomcat-embed-core-8.5.4.jar:8.5.4] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[na:1.8.0_91] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[na:1.8.0_91] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)[tomcat-embed-core-8.5.4.jar:8.5.4] at java.lang.Thread.run(Thread.java:745)[na:1.8.0_91]

    Users with the same issue

    DoktorDoener666
    DoktorDoener6661 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,