panjf2000 / gnet

🚀 gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go.
https://gnet.host
Apache License 2.0
9.7k stars 1.04k forks source link

[Bug]: Keepalive 设置不生效 #492

Closed iqinlongfei closed 10 months ago

iqinlongfei commented 1 year ago

Actions I've taken before I'm here

What happened?

TCP Server设置了5秒的KeepAlive时间,gnet.WithTCPKeepAlive(5*time.Second),在压测时,Client与Server大概建立了8000+条TCP连接,Client在运行中crash掉了,但Server端并没有按照设置的KeepAlive断开连接。

看了一下源码,TCP_KEEPINTVL和TCP_KEEPIDLE设置了5s,TCP_KEEPCNT没有设置,系统设置的是9。所以总的断开时间应该是5 + 5*9 = 50s。也就是说50s后,server端会断开连接。 image

但我抓包看,server端并没有发送keepalive,而是每隔120s进行一次重传。65.78是server,65.79是client image

Major version of gnet

v2

Specific version of gnet

v2.3.0

Operating system

Linux

OS version

Linux 5.4.56.bsk.9-amd64 x86_64

Go version

go version go1.18.2 linux/amd64

Relevant log output

没有设置logger

Code snippets (optional)

No response

How to Reproduce

  1. server设置Keepalive时间5s
  2. server与client建立1000条TCP连接。
  3. client端crash,确保不发送REST/FIN。测试时client通过XDP+用户态TCP协议栈,在crash时不会给server端发送RESET。
  4. 发现server端会保持1000条连接很长时间而且期间抓包也没有看到Keepalive报文

Does this issue reproduce with the latest release?

I haven't verified it with the latest release

panjf2000 commented 1 year ago

能提供一下可以复现这个问题的客户端和服务端代码吗?

iqinlongfei commented 1 year ago

代码需要整理一下,需要提取出来

panjf2000 commented 10 months ago

最近 gnet 对 TCP Keep-Alives 设置做了以下优化: #522,可以验证一下这个问题是否存在,我先关闭 issue 了,如果还有问题可以随时重新打开这个 issue