Skip to content

Modern Docker Management, Designed for Everyone

fix: sync timeout settings to all environments (#1628)

Kyle Mendellce115efb269f
diff --git a/backend/internal/bootstrap/jobs_bootstrap.go b/backend/internal/bootstrap/jobs_bootstrap.go
index 0bc6bd933..de50e83c3 100644
--- a/backend/internal/bootstrap/jobs_bootstrap.go
+++ b/backend/internal/bootstrap/jobs_bootstrap.go
@@ -2,7 +2,9 @@ package bootstrap
import (
"context"
+ "encoding/json"
"log/slog"
+ "net/http"
"github.com/getarcaneapp/arcane/backend/internal/config"
pkg_scheduler "github.com/getarcaneapp/arcane/backend/pkg/scheduler"
@@ -169,4 +171,46 @@ func setupSettingsCallbacks(appServices *Services, appConfig *config.Config, new
slog.WarnContext(ctx, "Failed to reschedule scheduled-prune job", "error", err)
}
}
+
+ // Only set up timeout sync callback on main instance (not in agent mode)
+ if !appConfig.AgentMode {
+ appServices.Settings.OnTimeoutSettingsChanged = func(ctx context.Context, timeoutSettings map[string]string) {
+ go syncTimeoutSettingsToAgentsInternal(context.WithoutCancel(ctx), appServices, timeoutSettings)
+ }
+ }
+}
+
+// syncTimeoutSettingsToAgentsInternal syncs timeout settings to all connected remote environments
+func syncTimeoutSettingsToAgentsInternal(ctx context.Context, appServices *Services, timeoutSettings map[string]string) {
+ envs, err := appServices.Environment.ListRemoteEnvironments(ctx)
+ if err != nil {
+ slog.WarnContext(ctx, "Failed to list remote environments for timeout sync", "error", err)
+ return
+ }
+
+ if len(envs) == 0 {
+ return
+ }
+
+ // Build the settings update payload
+ body, err := json.Marshal(timeoutSettings)
+ if err != nil {
+ slog.WarnContext(ctx, "Failed to marshal timeout settings for sync", "error", err)
+ return
+ }
+
+ slog.InfoContext(ctx, "Syncing timeout settings to remote environments", "count", len(envs), "settings", timeoutSettings)
+
+ for _, env := range envs {
+ _, statusCode, err := appServices.Environment.ProxyRequest(ctx, env.ID, http.MethodPut, "/api/environments/0/settings", body)
+ if err != nil {
+ slog.WarnContext(ctx, "Failed to sync timeout settings to environment", "environmentID", env.ID, "environmentName", env.Name, "error", err)
+ continue
+ }
+ if statusCode != http.StatusOK {
+ slog.WarnContext(ctx, "Environment returned non-OK status for timeout sync", "environmentID", env.ID, "environmentName", env.Name, "statusCode", statusCode)
+ continue
+ }
+ slog.DebugContext(ctx, "Successfully synced timeout settings to environment", "environmentID", env.ID, "environmentName", env.Name)
+ }
}
diff --git a/backend/internal/services/environment_service.go b/backend/internal/services/environment_service.go
index d2b7c9d1c..97009ce61 100644
--- a/backend/internal/services/environment_service.go
+++ b/backend/internal/services/environment_service.go
@@ -150,6 +150,20 @@ func (s *EnvironmentService) ListEnvironmentsPaginated(ctx context.Context, para
return out, paginationResp, nil
}
+// ListRemoteEnvironments returns all non-local, enabled environments for syncing purposes.
+func (s *EnvironmentService) ListRemoteEnvironments(ctx context.Context) ([]models.Environment, error) {
+ var envs []models.Environment
+ err := s.db.WithContext(ctx).
+ Model(&models.Environment{}).
+ Where("id != ?", "0").
+ Where("enabled = ?", true).
+ Find(&envs).Error
+ if err != nil {
+ return nil, fmt.Errorf("failed to list remote environments: %w", err)
+ }
+ return envs, nil
+}
+
func (s *EnvironmentService) UpdateEnvironment(ctx context.Context, id string, updates map[string]interface{}, userID, username *string) (*models.Environment, error) {
now := time.Now()
updates["updated_at"] = &now
diff --git a/backend/internal/services/settings_service.go b/backend/internal/services/settings_service.go
index c477bd561..fc72f9bb8 100644
--- a/backend/internal/services/settings_service.go
+++ b/backend/internal/services/settings_service.go
@@ -37,6 +37,7 @@ type SettingsService struct {
OnAutoUpdateSettingsChanged func(ctx context.Context)
OnProjectsDirectoryChanged func(ctx context.Context)
OnScheduledPruneSettingsChanged func(ctx context.Context)
+ OnTimeoutSettingsChanged func(ctx context.Context, timeoutSettings map[string]string)
}
func NewSettingsService(ctx context.Context, db *database.DB) (*SettingsService, error) {
@@ -430,7 +431,7 @@ func (s *SettingsService) UpdateSettings(ctx context.Context, updates settings.U
return nil, fmt.Errorf("failed to load current settings: %w", err)
}
- valuesToUpdate, changedPolling, changedAutoUpdate, changedScheduledPrune, err := s.prepareUpdateValues(updates, cfg, defaultCfg)
+ valuesToUpdate, changedPolling, changedAutoUpdate, changedScheduledPrune, changedTimeouts, err := s.prepareUpdateValues(updates, cfg, defaultCfg)
if err != nil {
return nil, err
}
@@ -464,11 +465,24 @@ func (s *SettingsService) UpdateSettings(ctx context.Context, updates settings.U
if slices.ContainsFunc(valuesToUpdate, func(sv models.SettingVariable) bool { return sv.Key == "projectsDirectory" }) && s.OnProjectsDirectoryChanged != nil {
s.OnProjectsDirectoryChanged(ctx)
}
+ if len(changedTimeouts) > 0 && s.OnTimeoutSettingsChanged != nil {
+ s.OnTimeoutSettingsChanged(ctx, changedTimeouts)
+ }
return settings.ToSettingVariableSlice(false, false), nil
}
-func (s *SettingsService) prepareUpdateValues(updates settings.Update, cfg, defaultCfg *models.Settings) ([]models.SettingVariable, bool, bool, bool, error) {
+// timeoutSettingKeys defines the keys for timeout settings that should be synced to agents
+var timeoutSettingKeys = []string{
+ "dockerApiTimeout",
+ "dockerImagePullTimeout",
+ "gitOperationTimeout",
+ "httpClientTimeout",
+ "registryTimeout",
+ "proxyRequestTimeout",
+}
+
+func (s *SettingsService) prepareUpdateValues(updates settings.Update, cfg, defaultCfg *models.Settings) ([]models.SettingVariable, bool, bool, bool, map[string]string, error) {
rt := reflect.TypeOf(updates)
rv := reflect.ValueOf(updates)
valuesToUpdate := make([]models.SettingVariable, 0)
@@ -476,6 +490,7 @@ func (s *SettingsService) prepareUpdateValues(updates settings.Update, cfg, defa
changedPolling := false
changedAutoUpdate := false
changedScheduledPrune := false
+ changedTimeouts := make(map[string]string)
for i := 0; i < rt.NumField(); i++ {
field := rt.Field(i)
@@ -495,7 +510,7 @@ func (s *SettingsService) prepareUpdateValues(updates settings.Update, cfg, defa
cronFields := []string{"scheduledPruneInterval", "autoUpdateInterval", "pollingInterval", "environmentHealthInterval", "eventCleanupInterval", "analyticsHeartbeatInterval"}
if slices.Contains(cronFields, key) && value != "" {
if _, err := cron.NewParser(cron.Second | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow).Parse(value); err != nil {
- return nil, false, false, false, fmt.Errorf("invalid cron expression for %s: %w", key, err)
+ return nil, false, false, false, nil, fmt.Errorf("invalid cron expression for %s: %w", key, err)
}
}
@@ -514,7 +529,7 @@ func (s *SettingsService) prepareUpdateValues(updates settings.Update, cfg, defa
if errors.Is(err, models.SettingSensitiveForbiddenError{}) {
continue
} else if err != nil {
- return nil, false, false, false, fmt.Errorf("failed to update in-memory config for key '%s': %w", key, err)
+ return nil, false, false, false, nil, fmt.Errorf("failed to update in-memory config for key '%s': %w", key, err)
}
valuesToUpdate = append(valuesToUpdate, models.SettingVariable{
@@ -530,9 +545,14 @@ func (s *SettingsService) prepareUpdateValues(updates settings.Update, cfg, defa
case "scheduledPruneEnabled", "scheduledPruneInterval", "scheduledPruneContainers", "scheduledPruneImages", "scheduledPruneVolumes", "scheduledPruneNetworks", "scheduledPruneBuildCache":
changedScheduledPrune = true
}
+
+ // Track timeout setting changes
+ if slices.Contains(timeoutSettingKeys, key) {
+ changedTimeouts[key] = valueToSave
+ }
}
- return valuesToUpdate, changedPolling, changedAutoUpdate, changedScheduledPrune, nil
+ return valuesToUpdate, changedPolling, changedAutoUpdate, changedScheduledPrune, changedTimeouts, nil
}
func (s *SettingsService) persistSettings(ctx context.Context, values []models.SettingVariable) error {
diff --git a/frontend/messages/en.json b/frontend/messages/en.json
index 83b928c63..9e7238081 100644
--- a/frontend/messages/en.json
+++ b/frontend/messages/en.json
@@ -1045,7 +1045,7 @@
"disk_usage_save_failed": "Failed to update disk usage path",
"directory_path": "Directory Path",
"_comment_settings_timeouts": "=== SETTINGS - TIMEOUTS ===",
- "timeouts_settings": "Timeout Settings",
+ "timeouts_settings": "Timeouts",
"timeouts_settings_description": "Configure operation timeouts for slow networks or hardware. All values are in seconds.",
"timeouts_save": "Timeout settings updated successfully",
"docker_api_timeout": "Docker API Timeout",
diff --git a/frontend/src/lib/config/navigation-config.ts b/frontend/src/lib/config/navigation-config.ts
index df8183328..fe61da668 100644
--- a/frontend/src/lib/config/navigation-config.ts
+++ b/frontend/src/lib/config/navigation-config.ts
@@ -1,7 +1,7 @@
import {
ApiKeyIcon,
ApperanceIcon,
- DockerBrandIcon,
+ JobsIcon,
UsersIcon,
SecurityIcon,
NotificationsIcon,
@@ -63,7 +63,8 @@ export const navigationItems: Record<string, NavigationItem[]> = {
shortcut: ['mod', 'shift', '3']
},
{ title: m.security_title(), url: '/settings/security', icon: SecurityIcon, shortcut: ['mod', 'shift', '4'] },
- { title: m.users_title(), url: '/settings/users', icon: UsersIcon, shortcut: ['mod', 'shift', '5'] }
+ { title: m.timeouts_settings(), url: '/settings/timeouts', icon: JobsIcon, shortcut: ['mod', 'shift', '5'] },
+ { title: m.users_title(), url: '/settings/users', icon: UsersIcon, shortcut: ['mod', 'shift', '6'] }
]
}
]
diff --git a/types/settings/settings.go b/types/settings/settings.go
index e17681d95..d7672cac0 100644
--- a/types/settings/settings.go
+++ b/types/settings/settings.go
@@ -241,4 +241,34 @@ type Update struct {
//
// Required: false
KeyboardShortcutsEnabled *string `json:"keyboardShortcutsEnabled,omitempty"`
+
+ // DockerApiTimeout is the timeout for Docker API operations in seconds.
+ //
+ // Required: false
+ DockerApiTimeout *string `json:"dockerApiTimeout,omitempty"`
+
+ // DockerImagePullTimeout is the timeout for Docker image pulls in seconds.
+ //
+ // Required: false
+ DockerImagePullTimeout *string `json:"dockerImagePullTimeout,omitempty"`
+
+ // GitOperationTimeout is the timeout for Git clone/fetch operations in seconds.
+ //
+ // Required: false
+ GitOperationTimeout *string `json:"gitOperationTimeout,omitempty"`
+
+ // HttpClientTimeout is the default timeout for HTTP requests in seconds.
+ //
+ // Required: false
+ HttpClientTimeout *string `json:"httpClientTimeout,omitempty"`
+
+ // RegistryTimeout is the timeout for container registry operations in seconds.
+ //
+ // Required: false
+ RegistryTimeout *string `json:"registryTimeout,omitempty"`
+
+ // ProxyRequestTimeout is the timeout for proxied requests to remote environments in seconds.
+ //
+ // Required: false
+ ProxyRequestTimeout *string `json:"proxyRequestTimeout,omitempty"`
}