fix(portforward): no longer stuck after failed port forwarding

This commit is contained in:
Quentin McGaw
2026-04-20 15:27:47 +00:00
parent 8bc2fbd487
commit 7eef1c89a7
2 changed files with 12 additions and 2 deletions
+1
View File
@@ -32,6 +32,7 @@ type Logger interface {
Info(s string)
Warn(s string)
Error(s string)
Errorf(format string, args ...any)
}
type Cmder interface {
+11 -2
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"net/http"
"sync"
"time"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/portforward/service"
@@ -87,6 +88,8 @@ func (l *Loop) run(runCtx context.Context, runDone chan<- struct{},
defer close(runDone)
var serviceRunError <-chan error
var retryAfter <-chan time.Time
const retryDelay = 5 * time.Second
for {
updateReceived := false
select {
@@ -105,10 +108,12 @@ func (l *Loop) run(runCtx context.Context, runDone chan<- struct{},
l.settingsMutex.Unlock()
case err := <-serviceRunError:
l.logger.Error(err.Error())
case <-retryAfter:
// Retry starting the service after a delay
retryAfter = nil
}
firstRun := serviceRunError == nil
if !firstRun {
if l.service != nil {
err := l.service.Stop()
if err != nil {
runErrorCh <- fmt.Errorf("stopping previous service: %w", err)
@@ -132,6 +137,10 @@ func (l *Loop) run(runCtx context.Context, runDone chan<- struct{},
err = fmt.Errorf("starting port forwarding service: %w", err)
}
updateResult <- err
} else if err != nil {
// Log the error and schedule a retry
l.logger.Errorf("starting port forwarding service: %s - retrying in %s", err, retryDelay)
retryAfter = time.After(retryDelay)
}
}
}