springboot配置http连接超时时间主动断开避免产生大量close_wait

背景

与客户端联调接口,通信方式使用http连接,客户端设置了发起请求后10s就断开连接,然后果不其然,我在服务端这边收到了大量的close_wait状态,最终导致接口不可用。

close_wait产生的原因就是客户端断开了连接但是没有发FIN给到服务端,所以服务端不知道还一直在跟客户端通信。

设置超时时间

  1. server.tomcat.connection-timeout=20000

  2. server.servlet.session.timeout=120s

server:
  port: 8988
  tomcat:
    uri-encoding: UTF-8
    connection-timeout: 20000   # 默认值20s 设置http超时时间(即keep-alive超时时间),没有任何活动则tomcat关闭连接
    protocol-header: HTTP/1.1
  servlet:
    session:
      timeout: 120s   # 会话超时时间,默认为30min  与客户端http断开

猜你喜欢

转载自blog.csdn.net/qq_36256590/article/details/130773174