加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

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

(2022-08-19 08:52:03)
分类: springboot
max-http-header-size设置 server.max-http-header-size=999999999 //953m JVM参数配置 -Xms800m -Xmx800m 写一个rest api @RestController("action") public class HttpHand...

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

 为了演示,本文例子比较极端,堆的大小直接小于buffer的大小,一次请求就oom,一般情况下就算堆的大小大于buffer的大小,如果这个max-size设置的不合理过大,随着请求并发的上升,buffer也会占用大量内存,从而导致oom。

max-size设置过小

http://www.hellojava.com/api/read.php?url=https://img2020.cnblogs.com/blog/737467/202004/737467-20200420233815506-7695789.png

 异常Request header is too large,导致post的header存不下来,要根据实际情况进行设置这个值。

文章出处:Java tomcat max-http-header-size配置导致的oom

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有