Skip to content

Commit 7354c83

Browse files
fix(transport, tcp): keep-alive bug that take 3 minutes to see the disconnection
1 parent 8d180f7 commit 7354c83

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

backend/pkg/transport/network/tcp/config.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ func NewClientConfig(laddr net.Addr) ClientConfig {
2424
Dialer: net.Dialer{
2525
Timeout: time.Second,
2626
LocalAddr: laddr,
27-
KeepAlive: time.Second, // Going under 1 second won't work in most systems
27+
KeepAlive: -1, // managed via KeepAliveConfig
28+
KeepAliveConfig: net.KeepAliveConfig{
29+
Enable: true,
30+
Idle: time.Second,
31+
Interval: time.Second,
32+
Count: 3,
33+
},
2834
},
2935

3036
Context: context.TODO(),
@@ -69,7 +75,13 @@ type ServerConfig struct {
6975
func NewServerConfig() ServerConfig {
7076
return ServerConfig{
7177
ListenConfig: net.ListenConfig{
72-
KeepAlive: time.Second,
78+
KeepAlive: -1, // managed via KeepAliveConfig
79+
KeepAliveConfig: net.KeepAliveConfig{
80+
Enable: true,
81+
Idle: time.Second,
82+
Interval: time.Second,
83+
Count: 3,
84+
},
7385
},
7486
Context: context.TODO(),
7587
}

0 commit comments

Comments
 (0)