我们将 Java 应用程序和 Nginx 作为反向代理安装在同一主机上。定期地,我们会发现CLOSE_WAIT连接长时间挂起:
$ ss -n4t | head
State Recv-Q Send-Q Local Address:Port Peer Address:Port
CLOSE-WAIT 1 0 127.0.0.1:8180 127.0.0.1:36599
CLOSE-WAIT 1 0 127.0.0.1:8180 127.0.0.1:36467
CLOSE-WAIT 1 0 127.0.0.1:8180 127.0.0.1:36154
Run Code Online (Sandbox Code Playgroud)
而且数量不断增加,那么应用程序就会出现问题。互联网上说:
Your server is failing to detect client disconnects, or ignoring them, and not closing the socket.
Run Code Online (Sandbox Code Playgroud)
Nginx 说:
2020/06/28 04:59:15 [error] 65506#0: *31719640 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 55.55.55.55, server: app.mycompany.com, request: "POST /url/url HTTP/1.0", upstream: …Run Code Online (Sandbox Code Playgroud)