embed tomcat bug:org.apache.catalina.connector.CoyoteAdapter checkRecycled

1.异常报错:

 org.apache.catalina.connector.CoyoteAdapter checkRecycled
信息: Encountered a non-recycled response and recycled it forcedly.
org.apache.catalina.connector.CoyoteAdapter$RecycleRequiredException
    at org.apache.catalina.connector.CoyoteAdapter.checkRecycled(CoyoteAdapter.java:632)
    at org.apache.coyote.http11.AbstractHttp11Processor.recycle(AbstractHttp11Processor.java:1821)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.release(Http11Protocol.java:140)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:720)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    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)

2.解决
1)查看报错源码

 @Override
    public void checkRecycled(org.apache.coyote.Request req,
            org.apache.coyote.Response res) {
        Request request = (Request) req.getNote(ADAPTER_NOTES);
        Response response = (Response) res.getNote(ADAPTER_NOTES);
        String messageKey = null;
        if (request != null && request.getHost() != null) {
            messageKey = "coyoteAdapter.checkRecycled.request";
        } else if (response != null && response.getContentWritten() != 0) {
            messageKey = "coyoteAdapter.checkRecycled.response";
        }
        if (messageKey != null) {
            // Log this request, as it has probably skipped the access log.
            // The log() method will take care of recycling.
            log(req, res, 0L);

            if (connector.getState().isAvailable()) {
                if (log.isInfoEnabled()) {
                    log.info(sm.getString(messageKey),
                            new RecycleRequiredException());
                }
            } else {
                // There may be some aborted requests.
                // When connector shuts down, the request and response will not
                // be reused, so there is no issue to warn about here.
                if (log.isDebugEnabled()) {
                    log.debug(sm.getString(messageKey),
                            new RecycleRequiredException());
                }
            }
        }
    }

报错点是由这个判断导致: response != null && response.getContentWritten() != 0


public long getContentWritten() {
        return outputBuffer.getContentWritten();
    }

  public long getContentWritten() {
        return bytesWritten + charsWritten;
    }

由于HttpServlet实现类中处理post请求时有调用过HttpServletResponse类的getWriter().write()和flush()方法,间隔20秒后在又使用了同一个对象的getWriter().write()和flush()方法,导致判断异常报错


上面的逻辑还会出现另外一个BUG

java.lang.NullPointerException: null
    at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:216) ~[tomcat-embed-core-7.0.73.jar:7.0.73]
    at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:480) ~[tomcat-embed-core-7.0.73.jar:7.0.73]
    at org.apache.coyote.http11.InternalOutputBuffer.flush(InternalOutputBuffer.java:120) ~[tomcat-embed-core-7.0.73.jar:7.0.73]
    at org.apache.coyote.http11.AbstractHttp11Processor.action(AbstractHttp11Processor.java:800) ~[tomcat-embed-core-7.0.73.jar:7.0.73]
    at org.apache.coyote.Response.action(Response.java:172) ~[tomcat-embed-core-7.0.73.jar:7.0.73]
    at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:366) ~[tomcat-embed-core-7.0.73.jar:7.0.73]
    at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:334) ~[tomcat-embed-core-7.0.73.jar:7.0.73]
    at org.apache.catalina.connector.CoyoteWriter.flush(CoyoteWriter.java:98) ~[tomcat-embed-core-7.0.73.jar:7.0.73]
    at com.joymeng.domain.system.tools.web.WaitingHttpResponse.flushReponse(WaitingHttpResponse.java:43) [bin/:?]
    at com.joymeng.domain.system.tools.web.WebService.timeoutWaitingHttpResponse(WebService.java:113) [bin/:?]
    at com.joymeng.domain.system.tools.web.WebService.tick(WebService.java:98) [bin/:?]
    at com.joymeng.domain.world.thread.SecondExecuteRunable.run(SecondExecuteRunable.java:15) [bin/:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.7.0_45]
    at java.util.concurrent.FutureTask.runAndReset(Unknown Source) [?:1.7.0_45]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source) [?:1.7.0_45]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) [?:1.7.0_45]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.7.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.7.0_45]
    at java.lang.Thread.run(Unknown Source) [?:1.7.0_45]
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zj380475045/article/details/76584542
文章标签: tomcat java
个人分类: java
上一篇【guava.jar】LoadingCache的使用
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭