[Fixed] Add retry to open tun
This commit is contained in:
parent
e92ef587bb
commit
b0fdd8dc47
1 changed files with 12 additions and 1 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/Dreamacro/clash/adapter/inbound"
|
"github.com/Dreamacro/clash/adapter/inbound"
|
||||||
"github.com/Dreamacro/clash/config"
|
"github.com/Dreamacro/clash/config"
|
||||||
|
@ -23,9 +24,19 @@ func New(conf config.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.Pack
|
||||||
var tunAdapter ipstack.TunAdapter
|
var tunAdapter ipstack.TunAdapter
|
||||||
|
|
||||||
device, err := dev.OpenTunDevice(tunAddress, autoRoute)
|
device, err := dev.OpenTunDevice(tunAddress, autoRoute)
|
||||||
|
if err != nil {
|
||||||
|
for i := 1; i < 3; i++ {
|
||||||
|
time.Sleep(time.Second * 1)
|
||||||
|
device, err = dev.OpenTunDevice(tunAddress, autoRoute)
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("can't open tun: %v", err)
|
return nil, fmt.Errorf("can't open tun: %v", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mtu, err := device.MTU()
|
mtu, err := device.MTU()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue