mirror of
https://github.com/safing/portmaster
synced 2025-09-01 18:19:12 +00:00
Retry saving the global config profile when it fails
This fixes an issue where the filter list IDs could not be resolved on startup
This commit is contained in:
parent
563bff1d95
commit
54daa8ba26
1 changed files with 30 additions and 3 deletions
|
@ -4,9 +4,10 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/safing/portbase/config"
|
||||
|
||||
"github.com/safing/portbase/modules"
|
||||
"github.com/safing/portmaster/intel/filterlists"
|
||||
"github.com/safing/portmaster/profile/endpoints"
|
||||
)
|
||||
|
@ -25,11 +26,15 @@ func registerConfigUpdater() error {
|
|||
"config",
|
||||
"config change",
|
||||
"update global config profile",
|
||||
updateGlobalConfigProfile,
|
||||
func(ctx context.Context, _ interface{}) error {
|
||||
return updateGlobalConfigProfile(ctx, nil)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func updateGlobalConfigProfile(ctx context.Context, data interface{}) error {
|
||||
const globalConfigProfileErrorID = "profile:global-profile-error"
|
||||
|
||||
func updateGlobalConfigProfile(ctx context.Context, task *modules.Task) error {
|
||||
cfgLock.Lock()
|
||||
defer cfgLock.Unlock()
|
||||
|
||||
|
@ -100,5 +105,27 @@ func updateGlobalConfigProfile(ctx context.Context, data interface{}) error {
|
|||
lastErr = err
|
||||
}
|
||||
|
||||
// If there was any error, try again later until it succeeds.
|
||||
if lastErr == nil {
|
||||
module.Resolve(globalConfigProfileErrorID)
|
||||
} else {
|
||||
// Create task after first failure.
|
||||
if task == nil {
|
||||
task = module.NewTask(
|
||||
"retry updating global config profile",
|
||||
updateGlobalConfigProfile,
|
||||
)
|
||||
}
|
||||
|
||||
// Schedule task.
|
||||
task.Schedule(time.Now().Add(15 * time.Second))
|
||||
|
||||
// Add module warning to inform user.
|
||||
module.Warning(
|
||||
globalConfigProfileErrorID,
|
||||
fmt.Sprintf("Failed to process global settings: %s", err),
|
||||
)
|
||||
}
|
||||
|
||||
return lastErr
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue