一个奇怪的400错误 java.lang.IllegalArgumentException: Request header is too large

奇怪特征:

1. 页面请求,返回400,接口测试,返回200

可以排除代码部分的验证问题,从response里看出,返回的不是json,而是tomcat的一个400错误页面。

那么问题基本锁定在tomcat身上。

但是tomcat我们是默认设置,没做任何修改,只能翻看日志,elasticsearch里也没找到error级别的错误,尝试看了下INFO级别的,好家伙

2020-10-29 22:44:05.243 INFO [quoteresource,,,] 1 --- [nio-8307-exec-9] o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level. java.lang.IllegalArgumentException: Request header is too large at org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:741) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33] at org.apache.coyote.http11.Http11InputBuffer.parseHeader(Http11InputBuffer.java:896) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33] at org.apache.coyote.http11.Http11InputBuffer.parseHeaders(Http11InputBuffer.java:584) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:283) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1594) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.33.jar!/:9.0.33] at java.base/java.lang.Thread.run(Thread.java:836) ~[na:na]

原来是request header太大了,我们的坑货架构师在token里加了一堆permission的信息,直接爆炸,但是木已成舟,只能加大size了。

解决方案:

Tomcat server.xml

Spring boot 1.4之后: 100kb

server.max-http-header-size=100000

Spring boot 1.4之前: 100kb

server.tomcat.max-http-header-size=100000

你可能感兴趣的:(java,tomcat)