Files
sub2api/backend/internal/repository/http_upstream_keepalive_linux.go
T
Anankke 94e56dd192 fix(upstream): do not fail the dial when TCP_USER_TIMEOUT cannot be set
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.
2026-11-14 07:03:11 -08:00

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
}