fix(portforward): rework run loop and fix deadlocks (#1874)

This commit is contained in:
Quentin McGaw
2023-09-23 12:57:12 +02:00
committed by GitHub
parent c435bbb32c
commit 71201411f4
30 changed files with 453 additions and 476 deletions

View File

@@ -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())
}
}
}