Sockopt: Cancel dialing after failed to bind interface, external controllers included such as TUN inbound's (#7173)

https://github.com/XTLS/Xray-core/pull/7161#issuecomment-6185101741

Fixes https://github.com/XTLS/Xray-core/issues/7160#issuecomment-6200788453

---------

Co-authored-by: Gleb <a1212gleb@gmail.com>
This commit is contained in:
风扇滑翔翼
2026-10-16 06:37:52 +00:00
committed by GitHub
co-authored by Gleb
parent d15966c76c
commit fe2ae23f42
6 changed files with 66 additions and 28 deletions
+7 -2
View File
@@ -144,7 +144,8 @@ func (t *Handler) Start() error {
errors.LogInfo(context.Background(), "[tun] falied to set interface > iface == nil")
return errors.New("iface not found")
}
return c.Control(func(fd uintptr) {
var controlErr, sockErr error
controlErr = c.Control(func(fd uintptr) {
addrPort, _ := netip.ParseAddrPort(address)
// skip loopback
if addrPort.Addr().IsLoopback() || strings.HasPrefix(strings.ToLower(address), "localhost:") {
@@ -152,9 +153,13 @@ func (t *Handler) Start() error {
}
err := setinterface(network, address, fd, iface)
if err != nil {
errors.LogInfoInner(context.Background(), err, "[tun] falied to set interface")
sockErr = errors.New("[tun] falied to set interface").Base(err)
}
})
if sockErr != nil {
return sockErr
}
return controlErr
})
}