最近线上服务器莫名出现某些请求出现502的现象,查看了nginx的error.log,发现看一个异常报错
upstream prematurely closed connection while reading response header from upstream(读取响应头时过早关闭连接)
应用程序方面也补抓到了一系列的异常
2022-03-17 08:38:08.943 [http-nio-8080-exec-30] ERROR o.a.c.c.C.[.[.[/heygood-crm].[dispatcherServlet]:175 - Servlet.service() for servlet [dispatcherServlet] in context with path [/heygood-crm] threw exception java.lang.NullPointerException: null at java.util.Objects.requireNonNull(Objects.java:203) at io.micrometer.core.instrument.ImmutableTag.<init>(ImmutableTag.java:35) at io.micrometer.core.instrument.Tag.of(Tag.java:29) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcTags.method(WebMvcTags.java:85) at org.springframework.boot.actuate.metrics.web.servlet.DefaultWebMvcTagsProvider.getTags(DefaultWebMvcTagsProvider.java:36) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.lambda$record$0(WebMvcMetricsFilter.java:166)2022-03-17 08:38:09.424 [http-nio-8080-exec-15] ERROR org.apache.coyote.http11.Http11Processor:175 - Error processing request java.lang.AssertionError: null at org.apache.catalina.mapper.Mapper.internalMap(Mapper.java:744) at org.apache.catalina.mapper.Mapper.map(Mapper.java:702) at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:696) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:337) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at java.lang.Thread.run(Thread.java:745)
了解了一下,是没有读取到相应的method方法以及获取请求头有问题
大概猜测了一下,应该是tcp请求还没有完成,但是相应的代理服务器关闭了请求,导致数据不完整会有这样的异常,出现这样的原因是因为我们用了阿里的slb负载均衡,而slb负载均衡对于http1.1的keep-live的时间为60s,
但是我们本地又做了一层的nginx,nigix默认的keep-live时间为75s,导致slb关闭但是本地nigix还未关闭数据传输出现问题,后面配置nginx中的keepalive_timeout 59s;
暂时解决了问题
具体还等待分析