java.lang.IllegalStateException: Cannot call sendError() after the response has been committed

sparkle picture sparkle · Feb 16, 2014 · Viewed 11.1k times · Source

I am working on indexing around 3 TB of data into apache solr. I am getting below error in my tomcat logs when the data size reached 14 GB. Is it possible to troubleshoot it? I am planning to move my index later to solr cloud.

> SEVERE: Servlet.service() for servlet [default] in context with path
> [/solr] threw exception java.lang.IllegalStateException: Cannot call
> sendError() after the response has been committed
>         at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:451)
>         at org.apache.solr.servlet.SolrDispatchFilter.sendError(SolrDispatchFilter.java:757)
>         at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:438)
>         at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:201)
>         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
>         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
>         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
>         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
>         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
>         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
>         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
>         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
>         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
>         at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
>         at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
>         at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
>         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>         at java.lang.Thread.run(Thread.java:662)

Answer

Steve McKay picture Steve McKay · Aug 6, 2014

This happens when Solr starts writing the response and then throws an exception. Then while trying to handle that exception, it throws another one. Solr's fallback in this situation is to basically throw up its hands and call HttpServletResponse#sendError(), which throws IllegalStateException because Solr has already written part of the response. As a side effect, the original exception is lost. Hooray!

If you're lucky, some other component logged the exception before throwing it up the stack. In that case the actual cause of this error will appear in the log shortly before the IllegalStateException. Otherwise it's time to set a breakpoint inside SolrDispatchFilter#sendError() and get a look at the exception before Solr swallows it.