fix(port-forward): clear port file instead of removing it

- Prevent port forwarding loop crash when trying to delete a directly bind mounted file
- See https://github.com/qdm12/gluetun/issues/2942#issuecomment-3468510402
This commit is contained in:
Quentin McGaw
2025-10-30 15:45:01 +00:00
parent c646ca5766
commit b9cc5c1fdc

View File

@@ -3,7 +3,6 @@ package service
import (
"context"
"fmt"
"os"
"time"
)
@@ -61,10 +60,10 @@ func (s *Service) cleanup() (err error) {
s.ports = nil
filepath := s.settings.Filepath
s.logger.Info("removing port file " + filepath)
err = os.Remove(filepath)
s.logger.Info("clearing port file " + filepath)
err = s.writePortForwardedFile(nil)
if err != nil {
return fmt.Errorf("removing port file: %w", err)
return fmt.Errorf("clearing port file: %w", err)
}
return nil