Javatomcatmax-http-header-size配置导致的oom

分类: springboot |
max-http-header-size设置
server.max-http-header-size=999999999 //953m
JVM参数配置
-Xms800m -Xmx800m
写一个rest api
@RestController("action") public class HttpHandler { @PostMapping("/get") public String get() { return "get"; } }
post访问
http://www.hellojava.com/api/read.php?url=https://img2020.cnblogs.com/blog/737467/202004/737467-20200420232157469-783626052.png
服务端OOM
java.lang.OutOfMemoryError: Java heap space at java.nio.HeapByteBuffer.<</span>init>(HeapByteBuffer.java:57) ~[na:1.8.0_152] at java.nio.ByteBuffer.allocate(ByteBuffer.java:335) ~[na:1.8.0_152] at org.apache.coyote.http11.Http11OutputBuffer.<</span>init>(Http11OutputBuffer.java:107) ~[tomcat-embed-core-9.0.33.jar:9.0.33] at org.apache.coyote.http11.Http11Processor.<</span>init>(Http11Processor.java:162) ~[tomcat-embed-core-9.0.33.jar:9.0.33] at org.apache.coyote.http11.AbstractHttp11Protocol.createProcessor(AbstractHttp11Protocol.java:990) ~[tomcat-embed-core-9.0.33.jar:9.0.33] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:853) ~[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.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_152] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_152] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.33.jar:9.0.33] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_152]
debug,分析
http://www.hellojava.com/api/read.php?url=https://img2020.cnblogs.com/blog/737467/202004/737467-20200420232356294-11381323.png
而jvm堆的最大大小是800m,第一时间就oom
其实http11InputBuffer也要初始化一个buffer,这个同样要占很多内存。
http://www.hellojava.com/api/read.php?url=https://img2020.cnblogs.com/blog/737467/202004/737467-20200420232533366-1888043983.png
max-size设置过小
http://www.hellojava.com/api/read.php?url=https://img2020.cnblogs.com/blog/737467/202004/737467-20200420233815506-7695789.png