fix(port-forwarding): loop exit from vpn loop

This commit is contained in:
Quentin McGaw
2022-04-25 08:23:56 +00:00
parent db91625de4
commit 2537cd5271

View File

@@ -52,10 +52,14 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
} }
stayHere := true stayHere := true
stopped := false
for stayHere { for stayHere {
select { select {
case <-ctx.Done(): case <-ctx.Done():
pfCancel() pfCancel()
if stopped {
return
}
<-errorCh <-errorCh
close(errorCh) close(errorCh)
close(portCh) close(portCh)
@@ -77,6 +81,7 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
l.firewallBlockPort(ctx) l.firewallBlockPort(ctx)
l.state.SetPortForwarded(0) l.state.SetPortForwarded(0)
l.stopped <- struct{}{} l.stopped <- struct{}{}
stopped = true
case port := <-portCh: case port := <-portCh:
l.logger.Info("port forwarded is " + strconv.Itoa(int(port))) l.logger.Info("port forwarded is " + strconv.Itoa(int(port)))
l.firewallBlockPort(ctx) l.firewallBlockPort(ctx)