mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-06 20:10:11 +02:00
fix(portforward): no longer stuck after failed port forwarding
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user