Skip to content

Commit

Permalink
Force delete the route twice to prevent failure
Browse files Browse the repository at this point in the history
  • Loading branch information
wheatevo committed Jan 19, 2021
1 parent 3528905 commit 27c2c2e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions network/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net"
"os/exec"
"time"
)

// Route describes a Windows network route
Expand All @@ -22,6 +23,12 @@ func NewRoute(network net.IPNet, ifaceID string) Route {
func (r *Route) Remove() ([]byte, error) {
out, err := exec.Command("netsh", "interface", "ipv4", "delete", "route", r.Network.String(), r.InterfaceID).Output()

// For some reason this requires multiple removals to work with the VPN, attempt a second removal if the first succeeds
if err == nil {
time.Sleep(500 * time.Millisecond)
exec.Command("netsh", "interface", "ipv4", "delete", "route", r.Network.String(), r.InterfaceID).Output()
}

return out, err
}

Expand Down

0 comments on commit 27c2c2e

Please sign in to comment.