mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
chore: retrying for "Cannot create a file when that file already exists."
This commit is contained in:
parent
02dd19e311
commit
846c2978fd
|
@ -182,7 +182,7 @@ func New(options config.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.P
|
|||
err = E.Cause(err, "build android rules")
|
||||
return
|
||||
}
|
||||
tunIf, err := tun.Open(tunOptions)
|
||||
tunIf, err := tunOpen(tunOptions)
|
||||
if err != nil {
|
||||
err = E.Cause(err, "configure tun interface")
|
||||
return
|
||||
|
|
11
listener/sing_tun/server_notwindows.go
Normal file
11
listener/sing_tun/server_notwindows.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
//go:build !windows
|
||||
|
||||
package sing_tun
|
||||
|
||||
import (
|
||||
tun "github.com/sagernet/sing-tun"
|
||||
)
|
||||
|
||||
func tunOpen(options tun.Options) (tun.Tun, error) {
|
||||
return tun.Open(options)
|
||||
}
|
|
@ -1,6 +1,29 @@
|
|||
package sing_tun
|
||||
|
||||
import tun "github.com/sagernet/sing-tun"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/Dreamacro/clash/log"
|
||||
|
||||
tun "github.com/sagernet/sing-tun"
|
||||
)
|
||||
|
||||
func tunOpen(options tun.Options) (tunIf tun.Tun, err error) {
|
||||
maxRetry := 3
|
||||
for i := 0; i < maxRetry; i++ {
|
||||
timeBegin := time.Now()
|
||||
tunIf, err = tun.Open(options)
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
timeEnd := time.Now()
|
||||
if timeEnd.Sub(timeBegin) < 1*time.Second { // retrying for "Cannot create a file when that file already exists."
|
||||
return
|
||||
}
|
||||
log.Warnln("Start Tun interface timeout: %s [retrying %d/%d]", err, i+1, maxRetry)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func init() {
|
||||
tun.TunnelType = InterfaceName
|
||||
|
|
Loading…
Reference in New Issue
Block a user