mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 08:05:12 +00:00
upstreamDialControl returned the setsockopt error, so a kernel or socket that refuses TCP_USER_TIMEOUT made every dial through newUpstreamDialer fail, where the keep-alive options alone never do that. A failure is now logged and the dial goes on without the option, as the standard library does for the keep-alive options.
29 lines
889 B
Go
29 lines
889 B
Go
//go:build linux
|
|
|
|
package repository
|
|
|
|
import (
|
|
"log/slog"
|
|
"syscall"
|
|
)
|
|
|
|
// tcpUserTimeout is TCP_USER_TIMEOUT from Linux include/uapi/linux/tcp.h; the
|
|
// standard library's syscall package does not define it on linux/amd64.
|
|
const tcpUserTimeout = 0x12
|
|
|
|
// upstreamDialControl sets TCP_USER_TIMEOUT on each upstream socket
|
|
// before it connects. A failure is logged and the dial goes on without the
|
|
// option, like the standard library does for the keep-alive options.
|
|
func upstreamDialControl(network, _ string, raw syscall.RawConn) error {
|
|
var sockErr error
|
|
if err := raw.Control(func(fd uintptr) {
|
|
sockErr = syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, tcpUserTimeout, int(upstreamTCPUserTimeout.Milliseconds()))
|
|
}); err != nil {
|
|
sockErr = err
|
|
}
|
|
if sockErr != nil {
|
|
slog.Warn("upstream_tcp_user_timeout_not_set", "network", network, "error", sockErr)
|
|
}
|
|
return nil
|
|
}
|