6

SpringBoot连接超时导致的502错误案例

 3 years ago
source link: https://renfufei.blog.csdn.net/article/details/108356534
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

1.问题描述

内部系统之间通过Nginx来实现路由转发。

但最近发现有一个系统,经常报502错误,每天达到上百次,完全无法忍受。

2. 原因排查

于是进行排查, 发现配置人员把连接超时时间(server.tomcat.connection-timeout)的单位,理解为秒,实际上是毫秒。

SpringBoot的部分配置如下:

# Tomcat
server:
  tomcat:
    uri-encoding: UTF-8
    max-threads: 1000
    min-spare-threads: 30
    connection-timeout: 60 # 错误在这里
  port: 18080
  servlet:
    context-path: /
  max-http-header-size: 102400

原来配置的值为 60,如果建立客户端连接的过程中,恰好碰到GC,并且加上GC的暂停时间总共达到60ms以上,Tomcat一看,超时了,就会导致建立连接失败,然后Nginx给客户端返回502错误。

3. 解决办法

修改连接超时时间,例如修改为【server.tomcat.connection-timeout=6000】, 如下所示:

# Tomcat
server:
  tomcat:
    uri-encoding: UTF-8
    max-threads: 1000
    min-spare-threads: 30
    connection-timeout: 6000
  port: 18080
  servlet:
    context-path: /
  max-http-header-size: 102400

问题解决。

当然,502错误也不止这个原因,需要排查Nginx链路。

作者: https://renfufei.blog.csdn.net/

时间: 2020年09月02日


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK