Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib/netutil/tcpdialer: enhance timeout handling
Use TCP_TIMEOUT_USER linux socket option to close connection based on user provided timeout. Using default timeout and keepalive flow is not sufficient to close connection in some cases which leads to timeout not being applied. Effectively, if connection stops processing new packets it will take up to 1 minute(with default configuration) instead of 1 second(based on keepalive value) to mark connection as broken. This can be tested by adding firewall rule to deny packets to vmstorage port: iptables -A INPUT -p tcp --dport {port} -j DROP To reverse this: iptables -D INPUT -p tcp --dport {port} -j DROP See: #4423 for more details. Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//go:build !linux | ||
// +build !linux | ||
|
||
package netutil | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
func setTCPUserTimeout(fd uintptr, timeout time.Duration) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package netutil | ||
|
||
import ( | ||
"syscall" | ||
"time" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func setTCPUserTimeout(fd uintptr, timeout time.Duration) error { | ||
return syscall.SetsockoptInt( | ||
int(fd), syscall.IPPROTO_TCP, unix.TCP_USER_TIMEOUT, int(timeout.Milliseconds())) | ||
} |