Fix: retry create TUN on Windows

This commit is contained in:
yaling888 2022-03-20 21:22:23 +08:00
parent bac04ab54b
commit 2c0890854e
4 changed files with 16 additions and 15 deletions

View file

@ -13,15 +13,10 @@ jobs:
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
#with:
# go-version: ${{ steps.version.outputs.go_version }}
with: with:
go-version: 1.18.x go-version: ${{ steps.version.outputs.go_version }}
- name: golangci-lint - name: golangci-lint
#uses: golangci/golangci-lint-action@v3 uses: golangci/golangci-lint-action@v3
#with: with:
# version: latest version: latest
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@ec95236
golangci-lint run ./...

View file

@ -11,10 +11,8 @@ jobs:
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
#with:
# go-version: ${{ steps.version.outputs.go_version }}
with: with:
go-version: 1.18.x go-version: ${{ steps.version.outputs.go_version }}
- name: Check out code into the Go module directory - name: Check out code into the Go module directory
uses: actions/checkout@v3 uses: actions/checkout@v3

View file

@ -4,9 +4,7 @@ linters:
- gofumpt - gofumpt
- staticcheck - staticcheck
- govet - govet
# - gci - gci
- gofmt
- goimports
linters-settings: linters-settings:
gci: gci:

View file

@ -5,6 +5,7 @@ package tun
import ( import (
"fmt" "fmt"
"runtime" "runtime"
"strings"
"github.com/Dreamacro/clash/common/pool" "github.com/Dreamacro/clash/common/pool"
"github.com/Dreamacro/clash/listener/tun/device" "github.com/Dreamacro/clash/listener/tun/device"
@ -50,9 +51,18 @@ func Open(name string, mtu uint32) (_ device.Device, err error) {
} }
nt, err := tun.CreateTUN(t.name, forcedMTU) // forcedMTU do not work on wintun, need to be setting by other way nt, err := tun.CreateTUN(t.name, forcedMTU) // forcedMTU do not work on wintun, need to be setting by other way
// retry if abnormal exit on Windows at last time
if err != nil && runtime.GOOS == "windows" &&
strings.HasSuffix(err.Error(), "file already exists.") {
nt, err = tun.CreateTUN(t.name, forcedMTU)
}
if err != nil { if err != nil {
return nil, fmt.Errorf("create tun: %w", err) return nil, fmt.Errorf("create tun: %w", err)
} }
t.nt = nt.(*tun.NativeTun) t.nt = nt.(*tun.NativeTun)
tunMTU, err := nt.MTU() tunMTU, err := nt.MTU()