fix(portforward): rework run loop and fix deadlocks (#1874)
This commit is contained in:
@@ -2,14 +2,14 @@ package vpn
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"errors"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func (l *Loop) cleanup(ctx context.Context, pfEnabled bool) {
|
||||
func (l *Loop) cleanup(vpnProvider string) {
|
||||
for _, vpnPort := range l.vpnInputPorts {
|
||||
err := l.fw.RemoveAllowedPort(ctx, vpnPort)
|
||||
err := l.fw.RemoveAllowedPort(context.Background(), vpnPort)
|
||||
if err != nil {
|
||||
l.logger.Error("cannot remove allowed input port from firewall: " + err.Error())
|
||||
}
|
||||
@@ -17,11 +17,11 @@ func (l *Loop) cleanup(ctx context.Context, pfEnabled bool) {
|
||||
|
||||
l.publicip.SetData(models.PublicIP{}) // clear public IP address data
|
||||
|
||||
if pfEnabled {
|
||||
const pfTimeout = 100 * time.Millisecond
|
||||
err := l.stopPortForwarding(ctx, pfTimeout)
|
||||
if err != nil {
|
||||
l.logger.Error("cannot stop port forwarding: " + err.Error())
|
||||
err := l.stopPortForwarding(vpnProvider)
|
||||
if err != nil {
|
||||
portForwardingAlreadyStopped := errors.Is(err, context.Canceled)
|
||||
if !portForwardingAlreadyStopped {
|
||||
l.logger.Error("stopping port forwarding: " + err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user