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

[Question]: TCP设置KeepAlive不生效 #491

Closed iqinlongfei closed 1 year ago

iqinlongfei commented 1 year ago

Actions I've taken before I'm here

Questions with details

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进行一次重传。 image

Code snippets (optional)

No response

panjf2000 commented 1 year ago

你是说客户端挂了之后,连接还长时间存在?

还有,请新开一个 issue,选择 bug 类型,填写必要的信息。

iqinlongfei commented 1 year ago

是的,客户端挂掉后,server端还会保持这些连接很长时间,没有按照设置的Keepalive进行处理。