[Fixed] Add retry to open tun

This commit is contained in:
gVisor bot 2021-12-09 22:52:11 +08:00
parent c9001cc60c
commit b22eeb86e2

View file

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"strings"
"time"
"github.com/Dreamacro/clash/adapter/inbound"
"github.com/Dreamacro/clash/config"
@ -24,7 +25,17 @@ func New(conf config.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.Pack
device, err := dev.OpenTunDevice(tunAddress, autoRoute)
if err != nil {
return nil, fmt.Errorf("can't open tun: %v", err)
for i := 1; i < 3; i++ {
time.Sleep(time.Second * 1)
device, err = dev.OpenTunDevice(tunAddress, autoRoute)
if err == nil {
break
}
}
if err != nil {
return nil, fmt.Errorf("can't open tun: %v", err)
}
}
mtu, err := device.MTU()