1. Problem description
Nginx is used to implement routing and forwarding between internal systems.
But recently, I found that there is a system that often reports 502 errors, reaching hundreds of times a day, which is completely unbearable.
2. Cause investigation
So I checked and found that the configuration personnel understood the unit of the connection timeout ( server.tomcat.connection-timeout
) as seconds, but it was actually milliseconds.
Part of the configuration of SpringBoot is as follows:
# 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
The original configuration value is that 60
if the GC happens to be encountered during the process of establishing the client connection, and the pause time of the GC reaches more than 60ms in total, Tomcat will see that it times out, which will cause the connection to fail to be established, and then Nginx will give the client end returns a 502 error.
3. Solutions
Modify the connection timeout time, for example, modify it to 【server.tomcat.connection-timeout=6000
】, as shown below:
# 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
problem solved.
Of course, the 502 error is not limited to this reason, and the Nginx link needs to be checked.
Author: https://renfufei.blog.csdn.net/
Time: September 2, 2020