Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
refactor: fix context patterns through codebase (#1450)
Kyle Mendelld4de38f9318c
diff --git a/backend/internal/api/ws_handler.go b/backend/internal/api/ws_handler.goindex 26c0ca3a8..c03120766 100644--- a/backend/internal/api/ws_handler.go+++ b/backend/internal/api/ws_handler.go@@ -182,6 +182,9 @@ func (h *WebSocketHandler) ProjectLogs(c *gin.Context) {}hub := h.startProjectLogHub(projectID, format, batched, follow, tail, since, timestamps)+ // WebSocket connections use context.Background() because they are long-lived and should not+ // be tied to the HTTP request context. Cleanup is handled via the hub's OnEmpty callback+ // which triggers when all clients disconnect.ws.ServeClient(context.Background(), hub, conn)}@@ -202,10 +205,10 @@ func (h *WebSocketHandler) startProjectLogHub(projectID, format string, batched,go ls.hub.Run(ctx)lines := make(chan string, 256)- go func() {+ go func(ctx context.Context) {defer close(lines)_ = h.projectService.StreamProjectLogs(ctx, projectID, lines, follow, tail, since, timestamps)- }()+ }(ctx)if format == "json" {msgs := make(chan ws.LogMessage, 256)@@ -291,6 +294,9 @@ func (h *WebSocketHandler) ContainerLogs(c *gin.Context) {}hub := h.startContainerLogHub(containerID, format, batched, follow, tail, since, timestamps)+ // WebSocket connections use context.Background() because they are long-lived and should not+ // be tied to the HTTP request context. Cleanup is handled via the hub's OnEmpty callback+ // which triggers when all clients disconnect.ws.ServeClient(context.Background(), hub, conn)}@@ -311,10 +317,10 @@ func (h *WebSocketHandler) startContainerLogHub(containerID, format string, batcgo ls.hub.Run(ctx)lines := make(chan string, 256)- go func() {+ go func(ctx context.Context) {defer close(lines)_ = h.containerService.StreamLogs(ctx, containerID, lines, follow, tail, since, timestamps)- }()+ }(ctx)if format == "json" {msgs := make(chan ws.LogMessage, 256)@@ -368,6 +374,9 @@ func (h *WebSocketHandler) ContainerStats(c *gin.Context) {}hub := h.startContainerStatsHub(containerID)+ // WebSocket connections use context.Background() because they are long-lived and should not+ // be tied to the HTTP request context. Cleanup is handled via the hub's OnEmpty callback+ // which triggers when all clients disconnect.ws.ServeClient(context.Background(), hub, conn)}@@ -384,10 +393,10 @@ func (h *WebSocketHandler) startContainerStatsHub(containerID string) *ws.Hub {go hub.Run(ctx)statsChan := make(chan interface{}, 64)- go func() {+ go func(ctx context.Context) {defer close(statsChan)_ = h.containerService.StreamStats(ctx, containerID, statsChan)- }()+ }(ctx)go func() {for {@@ -457,6 +466,12 @@ func (h *WebSocketHandler) ContainerExec(c *gin.Context) {defer close(done)buf := make([]byte, 4096)for {+ select {+ case <-ctx.Done():+ return+ default:+ }+n, err := stdout.Read(buf)if err != nil {return@@ -472,6 +487,12 @@ func (h *WebSocketHandler) ContainerExec(c *gin.Context) {// Read from websocket, write to containergo func() {for {+ select {+ case <-ctx.Done():+ return+ default:+ }+_, data, err := conn.ReadMessage()if err != nil {cancel()diff --git a/backend/internal/bootstrap/bootstrap.go b/backend/internal/bootstrap/bootstrap.goindex f21d41176..730248506 100644--- a/backend/internal/bootstrap/bootstrap.go+++ b/backend/internal/bootstrap/bootstrap.go@@ -32,7 +32,7 @@ func Bootstrap(ctx context.Context) error {appCtx, cancelApp := context.WithCancel(ctx)defer cancelApp()- db, err := initializeDBAndMigrate(cfg)+ db, err := initializeDBAndMigrate(appCtx, cfg)if err != nil {return fmt.Errorf("failed to initialize database: %w", err)}@@ -46,6 +46,9 @@ func Bootstrap(ctx context.Context) error {}(appCtx)httpClient := httputils.NewHTTPClient()+ if cfg.HTTPClientTimeout > 0 {+ httpClient = httputils.NewHTTPClientWithTimeout(time.Duration(cfg.HTTPClientTimeout) * time.Second)+ }appServices, dockerClientService, err := initializeServices(appCtx, db, cfg, httpClient)if err != nil {diff --git a/backend/internal/bootstrap/db_bootstrap.go b/backend/internal/bootstrap/db_bootstrap.goindex 957366de5..e4e34ad63 100644--- a/backend/internal/bootstrap/db_bootstrap.go+++ b/backend/internal/bootstrap/db_bootstrap.go@@ -1,6 +1,7 @@package bootstrapimport (+ "context""fmt""log/slog"@@ -8,8 +9,8 @@ import ("github.com/getarcaneapp/arcane/backend/internal/database")-func initializeDBAndMigrate(cfg *config.Config) (*database.DB, error) {- db, err := database.Initialize(cfg.DatabaseURL)+func initializeDBAndMigrate(ctx context.Context, cfg *config.Config) (*database.DB, error) {+ db, err := database.Initialize(ctx, cfg.DatabaseURL)if err != nil {return nil, fmt.Errorf("failed to initialize database: %w", err)}diff --git a/backend/internal/bootstrap/services_bootstrap.go b/backend/internal/bootstrap/services_bootstrap.goindex 35690025d..821cbe65b 100644--- a/backend/internal/bootstrap/services_bootstrap.go+++ b/backend/internal/bootstrap/services_bootstrap.go@@ -56,7 +56,7 @@ func initializeServices(ctx context.Context, db *database.DB, cfg *config.Configsvcs.CustomizeSearch = services.NewCustomizeSearchService()svcs.AppImages = services.NewApplicationImagesService(resources.FS, svcs.Settings)svcs.Font = services.NewFontService(resources.FS)- dockerClient := services.NewDockerClientService(db, cfg)+ dockerClient := services.NewDockerClientService(db, cfg, svcs.Settings)svcs.Docker = dockerClientsvcs.User = services.NewUserService(db)svcs.ContainerRegistry = services.NewContainerRegistryService(db)@@ -65,9 +65,9 @@ func initializeServices(ctx context.Context, db *database.DB, cfg *config.Configsvcs.ImageUpdate = services.NewImageUpdateService(db, svcs.Settings, svcs.ContainerRegistry, svcs.Docker, svcs.Event, svcs.Notification)svcs.Image = services.NewImageService(db, svcs.Docker, svcs.ContainerRegistry, svcs.ImageUpdate, svcs.Event)svcs.Project = services.NewProjectService(db, svcs.Settings, svcs.Event, svcs.Image, svcs.Docker)- svcs.Environment = services.NewEnvironmentService(db, httpClient, svcs.Docker, svcs.Event)- svcs.Container = services.NewContainerService(db, svcs.Event, svcs.Docker, svcs.Image)- svcs.Volume = services.NewVolumeService(db, svcs.Docker, svcs.Event)+ svcs.Environment = services.NewEnvironmentService(db, httpClient, svcs.Docker, svcs.Event, svcs.Settings)+ svcs.Container = services.NewContainerService(db, svcs.Event, svcs.Docker, svcs.Image, svcs.Settings)+ svcs.Volume = services.NewVolumeService(db, svcs.Docker, svcs.Event, svcs.Settings)svcs.Network = services.NewNetworkService(db, svcs.Docker, svcs.Event)svcs.Template = services.NewTemplateService(ctx, db, httpClient, svcs.Settings)svcs.Auth = services.NewAuthService(svcs.User, svcs.Settings, svcs.Event, cfg.JWTSecret, cfg)@@ -75,9 +75,9 @@ func initializeServices(ctx context.Context, db *database.DB, cfg *config.Configsvcs.ApiKey = services.NewApiKeyService(db, svcs.User)svcs.System = services.NewSystemService(db, svcs.Docker, svcs.Container, svcs.Image, svcs.Volume, svcs.Network, svcs.Settings)svcs.Version = services.NewVersionService(httpClient, cfg.UpdateCheckDisabled, config.Version, config.Revision, svcs.ContainerRegistry, svcs.Docker)- svcs.SystemUpgrade = services.NewSystemUpgradeService(svcs.Docker, svcs.Version, svcs.Event)+ svcs.SystemUpgrade = services.NewSystemUpgradeService(svcs.Docker, svcs.Version, svcs.Event, svcs.Settings)svcs.Updater = services.NewUpdaterService(db, svcs.Settings, svcs.Docker, svcs.Project, svcs.ImageUpdate, svcs.ContainerRegistry, svcs.Event, svcs.Image, svcs.Notification, svcs.SystemUpgrade)- svcs.GitRepository = services.NewGitRepositoryService(db, cfg.GitWorkDir, svcs.Event)+ svcs.GitRepository = services.NewGitRepositoryService(db, cfg.GitWorkDir, svcs.Event, svcs.Settings)svcs.GitOpsSync = services.NewGitOpsSyncService(db, svcs.GitRepository, svcs.Project, svcs.Event)return svcs, dockerClient, nildiff --git a/backend/internal/config/config.go b/backend/internal/config/config.goindex e6668ef2c..2113c6806 100644--- a/backend/internal/config/config.go+++ b/backend/internal/config/config.go@@ -56,6 +56,13 @@ type Config struct {FilePerm os.FileMode `env:"FILE_PERM" default:"0644"`DirPerm os.FileMode `env:"DIR_PERM" default:"0755"`GitWorkDir string `env:"GIT_WORK_DIR" default:"data/git"`++ DockerAPITimeout int `env:"DOCKER_API_TIMEOUT" default:"0"`+ DockerImagePullTimeout int `env:"DOCKER_IMAGE_PULL_TIMEOUT" default:"0"`+ GitOperationTimeout int `env:"GIT_OPERATION_TIMEOUT" default:"0"`+ HTTPClientTimeout int `env:"HTTP_CLIENT_TIMEOUT" default:"0"`+ RegistryTimeout int `env:"REGISTRY_TIMEOUT" default:"0"`+ ProxyRequestTimeout int `env:"PROXY_REQUEST_TIMEOUT" default:"0"`}func Load() *Config {@@ -199,6 +206,11 @@ func setFieldValue(field reflect.Value, value string) {field.SetUint(i)}+ case reflect.Int:+ if i, err := strconv.Atoi(value); err == nil {+ field.SetInt(int64(i))+ }+default:// Handle custom types based on underlying kindif field.Type().ConvertibleTo(reflect.TypeFor[string]()) {diff --git a/backend/internal/database/database.go b/backend/internal/database/database.goindex ffeab8917..001c677cd 100644--- a/backend/internal/database/database.go+++ b/backend/internal/database/database.go@@ -1,6 +1,7 @@package databaseimport (+ "context""errors""fmt""log/slog"@@ -35,12 +36,16 @@ func SetGormLogger(l logger.Interface) {customGormLogger = l}-func Initialize(databaseURL string) (*DB, error) {- db, err := connectDatabase(databaseURL)+func Initialize(ctx context.Context, databaseURL string) (*DB, error) {+ db, err := connectDatabase(ctx, databaseURL)if err != nil {return nil, fmt.Errorf("failed to connect to database: %w", err)}+ if err := ctx.Err(); err != nil {+ return nil, err+ }+// Get underlying sql.DB for migrationssqlDB, err := db.DB.DB()if err != nil {@@ -86,7 +91,7 @@ func Initialize(databaseURL string) (*DB, error) {return db, nil}-func connectDatabase(databaseURL string) (*DB, error) {+func connectDatabase(ctx context.Context, databaseURL string) (*DB, error) {var dialector gorm.Dialectorswitch {@@ -109,6 +114,9 @@ func connectDatabase(databaseURL string) (*DB, error) {var db *gorm.DBvar err errorfor i := 1; i <= 3; i++ {+ if err := ctx.Err(); err != nil {+ return nil, err+ }db, err = gorm.Open(dialector, &gorm.Config{Logger: customGormLogger,NowFunc: func() time.Time {@@ -123,7 +131,11 @@ func connectDatabase(databaseURL string) (*DB, error) {slog.Info("Failed to initialize database", "attempt", i)if i < 3 {- time.Sleep(3 * time.Second)+ select {+ case <-time.After(3 * time.Second):+ case <-ctx.Done():+ return nil, ctx.Err()+ }}}diff --git a/backend/internal/models/settings.go b/backend/internal/models/settings.goindex 081df54ac..c2838585e 100644--- a/backend/internal/models/settings.go+++ b/backend/internal/models/settings.go@@ -103,6 +103,14 @@ type Settings struct {// API Keys category (admin management page - no actual settings)ApiKeysCategoryPlaceholder SettingVariable `key:"apiKeysCategory,internal" meta:"label=API Keys;type=internal;keywords=api,keys,tokens,authentication,access,programmatic,integration;category=apikeys;description=Manage API keys for programmatic access" catmeta:"id=apikeys;title=API Keys;icon=apikey;url=/settings/api-keys;description=Create and manage API keys for programmatic access to Arcane"`++ // Timeout category+ DockerAPITimeout SettingVariable `key:"dockerApiTimeout,envOverride" meta:"label=Docker API Timeout;type=number;keywords=docker,api,timeout,seconds,list,operations;category=timeouts;description=Timeout for Docker list operations in seconds (default: 30)" catmeta:"id=timeouts;title=Timeouts;icon=clock;url=/settings/timeouts;description=Configure operation timeouts for slow networks or hardware"`+ DockerImagePullTimeout SettingVariable `key:"dockerImagePullTimeout,envOverride" meta:"label=Docker Image Pull Timeout;type=number;keywords=docker,image,pull,timeout,seconds,download;category=timeouts;description=Timeout for Docker image pulls in seconds (default: 600 = 10 minutes)"`+ GitOperationTimeout SettingVariable `key:"gitOperationTimeout,envOverride" meta:"label=Git Operation Timeout;type=number;keywords=git,clone,timeout,seconds,repository;category=timeouts;description=Timeout for Git clone/fetch operations in seconds (default: 300 = 5 minutes)"`+ HTTPClientTimeout SettingVariable `key:"httpClientTimeout,envOverride" meta:"label=HTTP Client Timeout;type=number;keywords=http,client,timeout,seconds,api,request;category=timeouts;description=Default timeout for HTTP requests in seconds (default: 30)"`+ RegistryTimeout SettingVariable `key:"registryTimeout,envOverride" meta:"label=Registry Timeout;type=number;keywords=registry,timeout,seconds,docker,auth;category=timeouts;description=Timeout for container registry operations in seconds (default: 30)"`+ ProxyRequestTimeout SettingVariable `key:"proxyRequestTimeout,envOverride" meta:"label=Proxy Request Timeout;type=number;keywords=proxy,request,timeout,seconds,forward;category=timeouts;description=Timeout for proxied requests in seconds (default: 60)"`}func (SettingVariable) TableName() string {diff --git a/backend/internal/services/container_service.go b/backend/internal/services/container_service.goindex c10cbae86..67ced79b1 100644--- a/backend/internal/services/container_service.go+++ b/backend/internal/services/container_service.go@@ -17,20 +17,28 @@ import ("github.com/getarcaneapp/arcane/backend/internal/database""github.com/getarcaneapp/arcane/backend/internal/models""github.com/getarcaneapp/arcane/backend/internal/utils/pagination"+ "github.com/getarcaneapp/arcane/backend/internal/utils/timeouts"containertypes "github.com/getarcaneapp/arcane/types/container""github.com/getarcaneapp/arcane/types/containerregistry"imagetypes "github.com/getarcaneapp/arcane/types/image")type ContainerService struct {- db *database.DB- dockerService *DockerClientService- eventService *EventService- imageService *ImageService+ db *database.DB+ dockerService *DockerClientService+ eventService *EventService+ imageService *ImageService+ settingsService *SettingsService}-func NewContainerService(db *database.DB, eventService *EventService, dockerService *DockerClientService, imageService *ImageService) *ContainerService {- return &ContainerService{db: db, eventService: eventService, dockerService: dockerService, imageService: imageService}+func NewContainerService(db *database.DB, eventService *EventService, dockerService *DockerClientService, imageService *ImageService, settingsService *SettingsService) *ContainerService {+ return &ContainerService{+ db: db,+ eventService: eventService,+ dockerService: dockerService,+ imageService: imageService,+ settingsService: settingsService,+ }}func (s *ContainerService) StartContainer(ctx context.Context, containerID string, user models.User) error {@@ -193,8 +201,16 @@ func (s *ContainerService) CreateContainer(ctx context.Context, config *containepullOptions = image.PullOptions{}}- reader, pullErr := dockerClient.ImagePull(ctx, config.Image, pullOptions)+ settings := s.settingsService.GetSettingsConfig()+ pullCtx, pullCancel := timeouts.WithTimeout(ctx, settings.DockerImagePullTimeout.AsInt(), timeouts.DefaultDockerImagePull)+ defer pullCancel()++ reader, pullErr := dockerClient.ImagePull(pullCtx, config.Image, pullOptions)if pullErr != nil {+ if errors.Is(pullCtx.Err(), context.DeadlineExceeded) {+ s.eventService.LogErrorEvent(ctx, models.EventTypeContainerError, "container", "", containerName, user.ID, user.Username, "0", pullErr, models.JSON{"action": "create", "image": config.Image, "step": "pull_image_timeout"})+ return nil, fmt.Errorf("image pull timed out for %s (increase DOCKER_IMAGE_PULL_TIMEOUT or setting)", config.Image)+ }s.eventService.LogErrorEvent(ctx, models.EventTypeContainerError, "container", "", containerName, user.ID, user.Username, "0", pullErr, models.JSON{"action": "create", "image": config.Image, "step": "pull_image"})return nil, fmt.Errorf("failed to pull image %s: %w", config.Image, pullErr)}diff --git a/backend/internal/services/docker_client_service.go b/backend/internal/services/docker_client_service.goindex 013e3b6d9..1d901fd99 100644--- a/backend/internal/services/docker_client_service.go+++ b/backend/internal/services/docker_client_service.go@@ -14,19 +14,22 @@ import ("github.com/getarcaneapp/arcane/backend/internal/config""github.com/getarcaneapp/arcane/backend/internal/database""github.com/getarcaneapp/arcane/backend/internal/utils/docker"+ "github.com/getarcaneapp/arcane/backend/internal/utils/timeouts")type DockerClientService struct {- db *database.DB- config *config.Config- client *client.Client- mu sync.Mutex+ db *database.DB+ config *config.Config+ settingsService *SettingsService+ client *client.Client+ mu sync.Mutex}-func NewDockerClientService(db *database.DB, cfg *config.Config) *DockerClientService {+func NewDockerClientService(db *database.DB, cfg *config.Config, settingsService *SettingsService) *DockerClientService {return &DockerClientService{- db: db,- config: cfg,+ db: db,+ config: cfg,+ settingsService: settingsService,}}@@ -63,7 +66,11 @@ func (s *DockerClientService) GetAllContainers(ctx context.Context) ([]containerreturn nil, 0, 0, 0, fmt.Errorf("failed to connect to Docker: %w", err)}- containers, err := dockerClient.ContainerList(ctx, container.ListOptions{All: true})+ settings := s.settingsService.GetSettingsConfig()+ apiCtx, cancel := timeouts.WithTimeout(ctx, settings.DockerAPITimeout.AsInt(), timeouts.DefaultDockerAPI)+ defer cancel()++ containers, err := dockerClient.ContainerList(apiCtx, container.ListOptions{All: true})if err != nil {return nil, 0, 0, 0, fmt.Errorf("failed to list Docker containers: %w", err)}@@ -87,7 +94,11 @@ func (s *DockerClientService) GetAllImages(ctx context.Context) ([]image.Summaryreturn nil, 0, 0, 0, fmt.Errorf("failed to connect to Docker: %w", err)}- images, err := dockerClient.ImageList(ctx, image.ListOptions{All: true})+ settings := s.settingsService.GetSettingsConfig()+ apiCtx, cancel := timeouts.WithTimeout(ctx, settings.DockerAPITimeout.AsInt(), timeouts.DefaultDockerAPI)+ defer cancel()++ images, err := dockerClient.ImageList(apiCtx, image.ListOptions{All: true})if err != nil {return nil, 0, 0, 0, fmt.Errorf("failed to list Docker containers: %w", err)}@@ -111,7 +122,11 @@ func (s *DockerClientService) GetAllNetworks(ctx context.Context) (_ []network.Sreturn nil, 0, 0, 0, fmt.Errorf("failed to connect to Docker: %w", err)}- containers, err := dockerClient.ContainerList(ctx, container.ListOptions{All: true})+ settings := s.settingsService.GetSettingsConfig()+ apiCtx, cancel := timeouts.WithTimeout(ctx, settings.DockerAPITimeout.AsInt(), timeouts.DefaultDockerAPI)+ defer cancel()++ containers, err := dockerClient.ContainerList(apiCtx, container.ListOptions{All: true})if err != nil {return nil, 0, 0, 0, fmt.Errorf("failed to list Docker containers: %w", err)}@@ -129,7 +144,7 @@ func (s *DockerClientService) GetAllNetworks(ctx context.Context) (_ []network.S}}- networks, err := dockerClient.NetworkList(ctx, network.ListOptions{})+ networks, err := dockerClient.NetworkList(apiCtx, network.ListOptions{})if err != nil {return nil, 0, 0, 0, fmt.Errorf("failed to list Docker networks: %w", err)}@@ -159,7 +174,11 @@ func (s *DockerClientService) GetAllVolumes(ctx context.Context) ([]*volume.Volureturn nil, 0, 0, 0, fmt.Errorf("failed to connect to Docker: %w", err)}- containers, err := dockerClient.ContainerList(ctx, container.ListOptions{All: true})+ settings := s.settingsService.GetSettingsConfig()+ apiCtx, cancel := timeouts.WithTimeout(ctx, settings.DockerAPITimeout.AsInt(), timeouts.DefaultDockerAPI)+ defer cancel()++ containers, err := dockerClient.ContainerList(apiCtx, container.ListOptions{All: true})if err != nil {return nil, 0, 0, 0, fmt.Errorf("failed to list Docker containers: %w", err)}@@ -172,7 +191,7 @@ func (s *DockerClientService) GetAllVolumes(ctx context.Context) ([]*volume.Volu}}- volResp, err := dockerClient.VolumeList(ctx, volume.ListOptions{})+ volResp, err := dockerClient.VolumeList(apiCtx, volume.ListOptions{})if err != nil {return nil, 0, 0, 0, fmt.Errorf("failed to list Docker volumes: %w", err)}diff --git a/backend/internal/services/environment_service.go b/backend/internal/services/environment_service.goindex c7e03a665..9850ce420 100644--- a/backend/internal/services/environment_service.go+++ b/backend/internal/services/environment_service.go@@ -17,6 +17,7 @@ import ("github.com/getarcaneapp/arcane/backend/internal/utils/crypto""github.com/getarcaneapp/arcane/backend/internal/utils/mapper""github.com/getarcaneapp/arcane/backend/internal/utils/pagination"+ "github.com/getarcaneapp/arcane/backend/internal/utils/timeouts""github.com/getarcaneapp/arcane/types/containerregistry""github.com/getarcaneapp/arcane/types/environment""github.com/getarcaneapp/arcane/types/gitops"@@ -25,17 +26,24 @@ import ()type EnvironmentService struct {- db *database.DB- httpClient *http.Client- dockerService *DockerClientService- eventService *EventService+ db *database.DB+ httpClient *http.Client+ dockerService *DockerClientService+ eventService *EventService+ settingsService *SettingsService}-func NewEnvironmentService(db *database.DB, httpClient *http.Client, dockerService *DockerClientService, eventService *EventService) *EnvironmentService {+func NewEnvironmentService(db *database.DB, httpClient *http.Client, dockerService *DockerClientService, eventService *EventService, settingsService *SettingsService) *EnvironmentService {if httpClient == nil {httpClient = http.DefaultClient}- return &EnvironmentService{db: db, httpClient: httpClient, dockerService: dockerService, eventService: eventService}+ return &EnvironmentService{+ db: db,+ httpClient: httpClient,+ dockerService: dockerService,+ eventService: eventService,+ settingsService: settingsService,+ }}func (s *EnvironmentService) EnsureLocalEnvironment(ctx context.Context, appUrl string) error {@@ -708,11 +716,16 @@ func (s *EnvironmentService) ProxyRequest(ctx context.Context, envID string, met}targetURL := strings.TrimRight(environment.ApiUrl, "/") + path++ settings := s.settingsService.GetSettingsConfig()+ proxyCtx, cancel := timeouts.WithTimeout(ctx, settings.ProxyRequestTimeout.AsInt(), timeouts.DefaultProxyRequest)+ defer cancel()+var bodyReader io.Readerif len(body) > 0 {bodyReader = bytes.NewReader(body)}- req, err := http.NewRequestWithContext(ctx, method, targetURL, bodyReader)+ req, err := http.NewRequestWithContext(proxyCtx, method, targetURL, bodyReader)if err != nil {return nil, 0, fmt.Errorf("failed to create request: %w", err)}diff --git a/backend/internal/services/git_repository_service.go b/backend/internal/services/git_repository_service.goindex a2091f577..bec6f7b03 100644--- a/backend/internal/services/git_repository_service.go+++ b/backend/internal/services/git_repository_service.go@@ -13,21 +13,24 @@ import ("github.com/getarcaneapp/arcane/backend/internal/utils/git""github.com/getarcaneapp/arcane/backend/internal/utils/mapper""github.com/getarcaneapp/arcane/backend/internal/utils/pagination"+ "github.com/getarcaneapp/arcane/backend/internal/utils/timeouts""github.com/getarcaneapp/arcane/types/gitops""gorm.io/gorm")type GitRepositoryService struct {- db *database.DB- gitClient *git.Client- eventService *EventService+ db *database.DB+ gitClient *git.Client+ eventService *EventService+ settingsService *SettingsService}-func NewGitRepositoryService(db *database.DB, workDir string, eventService *EventService) *GitRepositoryService {+func NewGitRepositoryService(db *database.DB, workDir string, eventService *EventService, settingsService *SettingsService) *GitRepositoryService {return &GitRepositoryService{- db: db,- gitClient: git.NewClient(workDir),- eventService: eventService,+ db: db,+ gitClient: git.NewClient(workDir),+ eventService: eventService,+ settingsService: settingsService,}}@@ -247,8 +250,11 @@ func (s *GitRepositoryService) DeleteRepository(ctx context.Context, id string)return nil}-func (s *GitRepositoryService) TestConnection(ctx context.Context, id string, branch string) error {+ settings := s.settingsService.GetSettingsConfig()+ ctx, cancel := timeouts.WithTimeout(ctx, settings.GitOperationTimeout.AsInt(), timeouts.DefaultGitOperation)+ defer cancel()+repository, err := s.GetRepositoryByID(ctx, id)if err != nil {return err@@ -263,7 +269,7 @@ func (s *GitRepositoryService) TestConnection(ctx context.Context, id string, brbranch = "main"}- err = s.gitClient.TestConnection(repository.URL, branch, authConfig)+ err = s.gitClient.TestConnection(ctx, repository.URL, branch, authConfig)if err != nil {// Log error eventresourceType := "git_repository"@@ -321,17 +327,21 @@ func (s *GitRepositoryService) GetAuthConfig(ctx context.Context, repository *mo}func (s *GitRepositoryService) ListBranches(ctx context.Context, id string) ([]gitops.BranchInfo, error) {- repository, err := s.GetRepositoryByID(ctx, id)+ settings := s.settingsService.GetSettingsConfig()+ listCtx, cancel := timeouts.WithTimeout(ctx, settings.GitOperationTimeout.AsInt(), timeouts.DefaultGitOperation)+ defer cancel()++ repository, err := s.GetRepositoryByID(listCtx, id)if err != nil {return nil, err}- authConfig, err := s.GetAuthConfig(ctx, repository)+ authConfig, err := s.GetAuthConfig(listCtx, repository)if err != nil {return nil, err}- branches, err := s.gitClient.ListBranches(repository.URL, authConfig)+ branches, err := s.gitClient.ListBranches(listCtx, repository.URL, authConfig)if err != nil {return nil, fmt.Errorf("failed to list branches: %w", err)}@@ -348,6 +358,10 @@ func (s *GitRepositoryService) ListBranches(ctx context.Context, id string) ([]g}func (s *GitRepositoryService) BrowseFiles(ctx context.Context, id, branch, path string) (*gitops.BrowseResponse, error) {+ settings := s.settingsService.GetSettingsConfig()+ ctx, cancel := timeouts.WithTimeout(ctx, settings.GitOperationTimeout.AsInt(), timeouts.DefaultGitOperation)+ defer cancel()+repository, err := s.GetRepositoryByID(ctx, id)if err != nil {return nil, err@@ -359,7 +373,7 @@ func (s *GitRepositoryService) BrowseFiles(ctx context.Context, id, branch, path}// Clone the repository- repoPath, err := s.gitClient.Clone(repository.URL, branch, authConfig)+ repoPath, err := s.gitClient.Clone(ctx, repository.URL, branch, authConfig)if err != nil {return nil, fmt.Errorf("failed to clone repository: %w", err)}@@ -371,7 +385,7 @@ func (s *GitRepositoryService) BrowseFiles(ctx context.Context, id, branch, path}()// Browse the tree- files, err := s.gitClient.BrowseTree(repoPath, path)+ files, err := s.gitClient.BrowseTree(ctx, repoPath, path)if err != nil {return nil, err}diff --git a/backend/internal/services/gitops_sync_service.go b/backend/internal/services/gitops_sync_service.goindex ff9e974a1..7d03d466e 100644--- a/backend/internal/services/gitops_sync_service.go+++ b/backend/internal/services/gitops_sync_service.go@@ -23,6 +23,8 @@ type GitOpsSyncService struct {eventService *EventService}+const defaultGitSyncTimeout = 5 * time.Minute+func NewGitOpsSyncService(db *database.DB, repoService *GitRepositoryService, projectService *ProjectService, eventService *EventService) *GitOpsSyncService {return &GitOpsSyncService{db: db,@@ -71,19 +73,25 @@ func (s *GitOpsSyncService) GetSyncByID(ctx context.Context, environmentID, id s}if err := q.First(&sync).Error; err != nil {if errors.Is(err, gorm.ErrRecordNotFound) {+ slog.WarnContext(ctx, "GitOps sync not found", "syncID", id, "environmentID", environmentID)return nil, fmt.Errorf("sync not found")}+ slog.ErrorContext(ctx, "Failed to get GitOps sync", "syncID", id, "environmentID", environmentID, "error", err)return nil, fmt.Errorf("failed to get sync: %w", err)}return &sync, nil}func (s *GitOpsSyncService) CreateSync(ctx context.Context, environmentID string, req gitops.CreateSyncRequest) (*models.GitOpsSync, error) {+ slog.InfoContext(ctx, "Creating GitOps sync", "environmentID", environmentID, "name", req.Name, "repositoryID", req.RepositoryID)+// Validate repository exists- _, err := s.repoService.GetRepositoryByID(ctx, req.RepositoryID)+ repo, err := s.repoService.GetRepositoryByID(ctx, req.RepositoryID)if err != nil {+ slog.ErrorContext(ctx, "Repository not found for GitOps sync", "repositoryID", req.RepositoryID, "error", err)return nil, fmt.Errorf("repository not found: %w", err)}+ slog.InfoContext(ctx, "Found repository for GitOps sync", "repositoryID", req.RepositoryID, "repositoryName", repo.Name)// Store the project name - use sync name if project name not providedprojectName := req.ProjectName@@ -111,8 +119,10 @@ func (s *GitOpsSyncService) CreateSync(ctx context.Context, environmentID string}if err := s.db.WithContext(ctx).Create(&sync).Error; err != nil {+ slog.ErrorContext(ctx, "Failed to create GitOps sync in database", "name", req.Name, "repositoryID", req.RepositoryID, "environmentID", environmentID, "error", err)return nil, fmt.Errorf("failed to create sync: %w", err)}+ slog.InfoContext(ctx, "GitOps sync created successfully", "syncID", sync.ID, "name", sync.Name)// Log eventresourceType := "git_sync"@@ -219,7 +229,10 @@ func (s *GitOpsSyncService) DeleteSync(ctx context.Context, environmentID, id st}func (s *GitOpsSyncService) PerformSync(ctx context.Context, environmentID, id string) (*gitops.SyncResult, error) {- sync, err := s.GetSyncByID(ctx, environmentID, id)+ syncCtx, cancel := context.WithTimeout(ctx, defaultGitSyncTimeout)+ defer cancel()++ sync, err := s.GetSyncByID(syncCtx, environmentID, id)if err != nil {return nil, err}@@ -232,59 +245,59 @@ func (s *GitOpsSyncService) PerformSync(ctx context.Context, environmentID, id s// Get repository and auth configrepository := sync.Repositoryif repository == nil {- return result, s.failSync(ctx, id, result, sync, "Repository not found", "repository not found")+ return result, s.failSync(syncCtx, id, result, sync, "Repository not found", "repository not found")}- authConfig, err := s.repoService.GetAuthConfig(ctx, repository)+ authConfig, err := s.repoService.GetAuthConfig(syncCtx, repository)if err != nil {- return result, s.failSync(ctx, id, result, sync, "Failed to get authentication config", err.Error())+ return result, s.failSync(syncCtx, id, result, sync, "Failed to get authentication config", err.Error())}// Clone the repository- repoPath, err := s.repoService.gitClient.Clone(repository.URL, sync.Branch, authConfig)+ repoPath, err := s.repoService.gitClient.Clone(syncCtx, repository.URL, sync.Branch, authConfig)if err != nil {- return result, s.failSync(ctx, id, result, sync, "Failed to clone repository", err.Error())+ return result, s.failSync(syncCtx, id, result, sync, "Failed to clone repository", err.Error())}defer func() {if cleanupErr := s.repoService.gitClient.Cleanup(repoPath); cleanupErr != nil {- slog.WarnContext(ctx, "Failed to cleanup repository", "path", repoPath, "error", cleanupErr)+ slog.WarnContext(syncCtx, "Failed to cleanup repository", "path", repoPath, "error", cleanupErr)}}()// Get the current commit hash- commitHash, err := s.repoService.gitClient.GetCurrentCommit(repoPath)+ commitHash, err := s.repoService.gitClient.GetCurrentCommit(syncCtx, repoPath)if err != nil {- slog.WarnContext(ctx, "Failed to get commit hash", "error", err)+ slog.WarnContext(syncCtx, "Failed to get commit hash", "error", err)commitHash = ""}// Check if compose file exists- if !s.repoService.gitClient.FileExists(repoPath, sync.ComposePath) {+ if !s.repoService.gitClient.FileExists(syncCtx, repoPath, sync.ComposePath) {errMsg := fmt.Sprintf("compose file not found: %s", sync.ComposePath)- return result, s.failSync(ctx, id, result, sync, fmt.Sprintf("Compose file not found at %s", sync.ComposePath), errMsg)+ return result, s.failSync(syncCtx, id, result, sync, fmt.Sprintf("Compose file not found at %s", sync.ComposePath), errMsg)}// Read compose file content- composeContent, err := s.repoService.gitClient.ReadFile(repoPath, sync.ComposePath)+ composeContent, err := s.repoService.gitClient.ReadFile(syncCtx, repoPath, sync.ComposePath)if err != nil {- return result, s.failSync(ctx, id, result, sync, "Failed to read compose file", err.Error())+ return result, s.failSync(syncCtx, id, result, sync, "Failed to read compose file", err.Error())}// Get or create project- project, err := s.getOrCreateProject(ctx, sync, id, composeContent, result)+ project, err := s.getOrCreateProject(syncCtx, sync, id, composeContent, result)if err != nil {return result, err}// Update sync status- s.updateSyncStatus(ctx, id, "success", "", commitHash)+ s.updateSyncStatus(syncCtx, id, "success", "", commitHash)result.Success = trueresult.Message = fmt.Sprintf("Successfully synced compose file from %s to project %s", sync.ComposePath, project.Name)// Log success eventresourceType := "git_sync"- _, _ = s.eventService.CreateEvent(ctx, CreateEventRequest{+ _, _ = s.eventService.CreateEvent(syncCtx, CreateEventRequest{Type: models.EventTypeGitSyncRun,Severity: models.EventSeveritySuccess,Title: "Git sync completed",@@ -296,7 +309,7 @@ func (s *GitOpsSyncService) PerformSync(ctx context.Context, environmentID, id sUsername: &systemUser.Username,})- slog.InfoContext(ctx, "GitOps sync completed", "syncId", id, "project", project.Name)+ slog.InfoContext(syncCtx, "GitOps sync completed", "syncId", id, "project", project.Name)return result, nil}@@ -383,7 +396,10 @@ func (s *GitOpsSyncService) SyncAllEnabled(ctx context.Context) error {}func (s *GitOpsSyncService) BrowseFiles(ctx context.Context, environmentID, id string, path string) (*gitops.BrowseResponse, error) {- sync, err := s.GetSyncByID(ctx, environmentID, id)+ browseCtx, cancel := context.WithTimeout(ctx, defaultGitSyncTimeout)+ defer cancel()++ sync, err := s.GetSyncByID(browseCtx, environmentID, id)if err != nil {return nil, err}@@ -393,24 +409,24 @@ func (s *GitOpsSyncService) BrowseFiles(ctx context.Context, environmentID, id sreturn nil, fmt.Errorf("repository not found")}- authConfig, err := s.repoService.GetAuthConfig(ctx, repository)+ authConfig, err := s.repoService.GetAuthConfig(browseCtx, repository)if err != nil {return nil, err}// Clone the repository- repoPath, err := s.repoService.gitClient.Clone(repository.URL, sync.Branch, authConfig)+ repoPath, err := s.repoService.gitClient.Clone(browseCtx, repository.URL, sync.Branch, authConfig)if err != nil {return nil, fmt.Errorf("failed to clone repository: %w", err)}defer func() {if cleanupErr := s.repoService.gitClient.Cleanup(repoPath); cleanupErr != nil {- slog.WarnContext(ctx, "Failed to cleanup repository", "path", repoPath, "error", cleanupErr)+ slog.WarnContext(browseCtx, "Failed to cleanup repository", "path", repoPath, "error", cleanupErr)}}()// Browse the tree- files, err := s.repoService.gitClient.BrowseTree(repoPath, path)+ files, err := s.repoService.gitClient.BrowseTree(browseCtx, repoPath, path)if err != nil {return nil, err}diff --git a/backend/internal/services/settings_service.go b/backend/internal/services/settings_service.goindex bfcd23901..d0a56ec61 100644--- a/backend/internal/services/settings_service.go+++ b/backend/internal/services/settings_service.go@@ -125,6 +125,13 @@ func (s *SettingsService) getDefaultSettings() *models.Settings {MaxImageUploadSize: models.SettingVariable{Value: "500"},EnvironmentHealthInterval: models.SettingVariable{Value: "2"},+ DockerAPITimeout: models.SettingVariable{Value: "30"},+ DockerImagePullTimeout: models.SettingVariable{Value: "600"},+ GitOperationTimeout: models.SettingVariable{Value: "300"},+ HTTPClientTimeout: models.SettingVariable{Value: "30"},+ RegistryTimeout: models.SettingVariable{Value: "30"},+ ProxyRequestTimeout: models.SettingVariable{Value: "60"},+InstanceID: models.SettingVariable{Value: ""},}}diff --git a/backend/internal/services/system_upgrade_service.go b/backend/internal/services/system_upgrade_service.goindex 75b0fd3f5..580f5df2d 100644--- a/backend/internal/services/system_upgrade_service.go+++ b/backend/internal/services/system_upgrade_service.go@@ -17,6 +17,7 @@ import (mounttypes "github.com/docker/docker/api/types/mount""github.com/getarcaneapp/arcane/backend/internal/models"dockerutils "github.com/getarcaneapp/arcane/backend/internal/utils/docker"+ "github.com/getarcaneapp/arcane/backend/internal/utils/timeouts")var (@@ -28,21 +29,24 @@ var ()type SystemUpgradeService struct {- upgrading atomic.Bool- dockerService *DockerClientService- versionService *VersionService- eventService *EventService+ upgrading atomic.Bool+ dockerService *DockerClientService+ versionService *VersionService+ eventService *EventService+ settingsService *SettingsService}func NewSystemUpgradeService(dockerService *DockerClientService,versionService *VersionService,eventService *EventService,+ settingsService *SettingsService,) *SystemUpgradeService {return &SystemUpgradeService{- dockerService: dockerService,- versionService: versionService,- eventService: eventService,+ dockerService: dockerService,+ versionService: versionService,+ eventService: eventService,+ settingsService: settingsService,}}@@ -121,8 +125,16 @@ func (s *SystemUpgradeService) TriggerUpgradeViaCLI(ctx context.Context, user mo// Pull the upgrader image first to ensure it existsslog.Info("Pulling upgrader image", "image", ArcaneUpgraderImage)- pullReader, err := dockerClient.ImagePull(ctx, ArcaneUpgraderImage, imagetypes.PullOptions{})++ settings := s.settingsService.GetSettingsConfig()+ pullCtx, pullCancel := timeouts.WithTimeout(ctx, settings.DockerImagePullTimeout.AsInt(), timeouts.DefaultDockerImagePull)+ defer pullCancel()++ pullReader, err := dockerClient.ImagePull(pullCtx, ArcaneUpgraderImage, imagetypes.PullOptions{})if err != nil {+ if errors.Is(pullCtx.Err(), context.DeadlineExceeded) {+ return fmt.Errorf("upgrader image pull timed out for %s (increase DOCKER_IMAGE_PULL_TIMEOUT or setting)", ArcaneUpgraderImage)+ }return fmt.Errorf("pull upgrader image: %w", err)}// Drain the reader to complete the pulldiff --git a/backend/internal/services/system_upgrade_service_test.go b/backend/internal/services/system_upgrade_service_test.goindex 661605e16..0f35d0b02 100644--- a/backend/internal/services/system_upgrade_service_test.go+++ b/backend/internal/services/system_upgrade_service_test.go@@ -8,7 +8,7 @@ import (// TestSystemUpgradeService_UpgradeFlag tests the upgrading flag behaviorfunc TestSystemUpgradeService_UpgradeFlag(t *testing.T) {- s := NewSystemUpgradeService(nil, nil, nil)+ s := NewSystemUpgradeService(nil, nil, nil, nil)// Initially should be falserequire.False(t, s.upgrading.Load())@@ -24,7 +24,7 @@ func TestSystemUpgradeService_UpgradeFlag(t *testing.T) {// TestSystemUpgradeService_Initialization tests proper initializationfunc TestSystemUpgradeService_Initialization(t *testing.T) {- s := NewSystemUpgradeService(nil, nil, nil)+ s := NewSystemUpgradeService(nil, nil, nil, nil)require.NotNil(t, s)require.False(t, s.upgrading.Load())@@ -48,7 +48,7 @@ func TestSystemUpgradeService_ErrorVariables(t *testing.T) {// TestSystemUpgradeService_UpgradingFlag_ConcurrentAccess tests upgrading flagfunc TestSystemUpgradeService_UpgradingFlag_ConcurrentAccess(t *testing.T) {- s := NewSystemUpgradeService(nil, nil, nil)+ s := NewSystemUpgradeService(nil, nil, nil, nil)// Test initial staterequire.False(t, s.upgrading.Load(), "upgrading flag should start as false")@@ -64,7 +64,7 @@ func TestSystemUpgradeService_UpgradingFlag_ConcurrentAccess(t *testing.T) {// TestSystemUpgradeService_CompareAndSwap tests atomic CompareAndSwap operationfunc TestSystemUpgradeService_CompareAndSwap(t *testing.T) {- s := NewSystemUpgradeService(nil, nil, nil)+ s := NewSystemUpgradeService(nil, nil, nil, nil)// Test successful CompareAndSwap from false to trueswapped := s.upgrading.CompareAndSwap(false, true)@@ -85,7 +85,7 @@ func TestSystemUpgradeService_CompareAndSwap(t *testing.T) {// TestSystemUpgradeService_Services tests that services are stored correctlyfunc TestSystemUpgradeService_Services(t *testing.T) {// Create upgrade service with nil services (valid for testing initialization)- s := NewSystemUpgradeService(nil, nil, nil)+ s := NewSystemUpgradeService(nil, nil, nil, nil)// Verify service is created and initialized properlyrequire.NotNil(t, s)@@ -94,7 +94,7 @@ func TestSystemUpgradeService_Services(t *testing.T) {// TestSystemUpgradeService_ConcurrentUpgradeAttempts tests that concurrent upgrade attempts are preventedfunc TestSystemUpgradeService_ConcurrentUpgradeAttempts(t *testing.T) {- s := NewSystemUpgradeService(nil, nil, nil)+ s := NewSystemUpgradeService(nil, nil, nil, nil)// Simulate first upgrade startingsuccess := s.upgrading.CompareAndSwap(false, true)@@ -125,7 +125,7 @@ func TestSystemUpgradeService_UpgradeInProgressError(t *testing.T) {// TestSystemUpgradeService_AtomicOperations tests atomic.Bool operationsfunc TestSystemUpgradeService_AtomicOperations(t *testing.T) {- s := NewSystemUpgradeService(nil, nil, nil)+ s := NewSystemUpgradeService(nil, nil, nil, nil)// Test Loadrequire.False(t, s.upgrading.Load())diff --git a/backend/internal/services/version_service.go b/backend/internal/services/version_service.goindex 81e7f01e1..ece9aef81 100644--- a/backend/internal/services/version_service.go+++ b/backend/internal/services/version_service.go@@ -25,7 +25,7 @@ import (const (versionTTL = 3 * time.HourversionCheckURL = "https://api.github.com/repos/getarcaneapp/arcane/releases/latest"- defaultRequestTimeout = 5 * time.Second+ defaultRequestTimeout = 15 * time.Second)type VersionService struct {diff --git a/backend/internal/services/volume_service.go b/backend/internal/services/volume_service.goindex 768f4db6e..085b0f084 100644--- a/backend/internal/services/volume_service.go+++ b/backend/internal/services/volume_service.go@@ -15,20 +15,23 @@ import ("github.com/getarcaneapp/arcane/backend/internal/models""github.com/getarcaneapp/arcane/backend/internal/utils/docker""github.com/getarcaneapp/arcane/backend/internal/utils/pagination"+ "github.com/getarcaneapp/arcane/backend/internal/utils/timeouts"volumetypes "github.com/getarcaneapp/arcane/types/volume")type VolumeService struct {- db *database.DB- dockerService *DockerClientService- eventService *EventService+ db *database.DB+ dockerService *DockerClientService+ eventService *EventService+ settingsService *SettingsService}-func NewVolumeService(db *database.DB, dockerService *DockerClientService, eventService *EventService) *VolumeService {+func NewVolumeService(db *database.DB, dockerService *DockerClientService, eventService *EventService, settingsService *SettingsService) *VolumeService {return &VolumeService{- db: db,- dockerService: dockerService,- eventService: eventService,+ db: db,+ dockerService: dockerService,+ eventService: eventService,+ settingsService: settingsService,}}@@ -411,15 +414,19 @@ func (s *VolumeService) ListVolumesPaginated(ctx context.Context, params paginatvolChan := make(chan volumeListResult, 1)containerChan := make(chan containerMapResult, 1)- go func() {+ settings := s.settingsService.GetSettingsConfig()+ apiCtx, cancel := timeouts.WithTimeout(ctx, settings.DockerAPITimeout.AsInt(), timeouts.DefaultDockerAPI)+ defer cancel()++ go func(ctx context.Context) {volListBody, err := dockerClient.VolumeList(ctx, volume.ListOptions{})volChan <- volumeListResult{volumes: volListBody.Volumes, err: err}- }()+ }(apiCtx)- go func() {+ go func(ctx context.Context) {containerMap, err := s.buildVolumeContainerMap(ctx, dockerClient)containerChan <- containerMapResult{containerMap: containerMap, err: err}- }()+ }(apiCtx)// Wait for both resultsvolResult := <-volChan@@ -437,7 +444,7 @@ func (s *VolumeService) ListVolumesPaginated(ctx context.Context, params paginat// Fetch usage data if sorting by size is requestedvar usageVolumes []volume.Volumeif params.Sort == "size" {- if uv, err := docker.GetVolumeUsageData(ctx, dockerClient); err == nil {+ if uv, err := docker.GetVolumeUsageData(apiCtx, dockerClient); err == nil {usageVolumes = uv} else {slog.WarnContext(ctx, "failed to get volume usage data for sorting", "error", err.Error())diff --git a/backend/internal/utils/git/git.go b/backend/internal/utils/git/git.goindex 90c7b672a..b0b204dd7 100644--- a/backend/internal/utils/git/git.go+++ b/backend/internal/utils/git/git.go@@ -1,6 +1,7 @@package gitimport (+ "context""errors""fmt""net"@@ -206,7 +207,17 @@ func addHostKey(knownHostsPath, hostname string, key gossh.PublicKey) (err error}// Clone clones a repository to a temporary directory-func (c *Client) Clone(url, branch string, auth AuthConfig) (string, error) {+func (c *Client) Clone(ctx context.Context, url, branch string, auth AuthConfig) (string, error) {+ if _, hasDeadline := ctx.Deadline(); !hasDeadline {+ var cancel context.CancelFunc+ ctx, cancel = context.WithTimeout(ctx, 5*time.Minute)+ defer cancel()+ }++ if err := ctx.Err(); err != nil {+ return "", err+ }+// Create a temporary directoryworkDir := c.workDirif workDir == "" {@@ -241,7 +252,7 @@ func (c *Client) Clone(url, branch string, auth AuthConfig) (string, error) {cloneOptions.SingleBranch = true}- _, err = git.PlainClone(tmpDir, false, cloneOptions)+ _, err = git.PlainCloneContext(ctx, tmpDir, false, cloneOptions)if err != nil {os.RemoveAll(tmpDir)return "", fmt.Errorf("failed to clone repository: %w", err)@@ -251,7 +262,10 @@ func (c *Client) Clone(url, branch string, auth AuthConfig) (string, error) {}// GetCurrentCommit returns the HEAD commit hash of a cloned repository-func (c *Client) GetCurrentCommit(repoPath string) (string, error) {+func (c *Client) GetCurrentCommit(ctx context.Context, repoPath string) (string, error) {+ if err := ctx.Err(); err != nil {+ return "", err+ }repo, err := git.PlainOpen(repoPath)if err != nil {return "", fmt.Errorf("failed to open repository: %w", err)@@ -272,7 +286,10 @@ type BranchInfo struct {}// ListBranches lists all branches in a remote repository-func (c *Client) ListBranches(url string, auth AuthConfig) ([]BranchInfo, error) {+func (c *Client) ListBranches(ctx context.Context, url string, auth AuthConfig) ([]BranchInfo, error) {+ if err := ctx.Err(); err != nil {+ return nil, err+ }authMethod, err := c.getAuth(auth)if err != nil {return nil, err@@ -289,7 +306,10 @@ func (c *Client) ListBranches(url string, auth AuthConfig) ([]BranchInfo, error)listOptions.Auth = authMethod}- refs, err := rem.List(listOptions)+ listCtx, cancel := context.WithTimeout(ctx, 60*time.Second)+ defer cancel()++ refs, err := rem.ListContext(listCtx, listOptions)if err != nil {return nil, fmt.Errorf("failed to list remote references: %w", err)}@@ -358,7 +378,10 @@ func ValidatePath(repoPath, requestedPath string) error {}// BrowseTree returns the file tree at the specified path-func (c *Client) BrowseTree(repoPath, targetPath string) ([]gitops.FileTreeNode, error) {+func (c *Client) BrowseTree(ctx context.Context, repoPath, targetPath string) ([]gitops.FileTreeNode, error) {+ if err := ctx.Err(); err != nil {+ return nil, err+ }// Validate path to prevent traversalif err := ValidatePath(repoPath, targetPath); err != nil {return nil, err@@ -383,6 +406,11 @@ func (c *Client) BrowseTree(repoPath, targetPath string) ([]gitops.FileTreeNode,var nodes []gitops.FileTreeNodefor _, entry := range entries {+ select {+ case <-ctx.Done():+ return nil, ctx.Err()+ default:+ }// Skip .git directoryif entry.Name() == ".git" {continue@@ -426,8 +454,12 @@ type CommitInfo struct {}// TestConnection tests if the repository can be accessed with the given credentials-func (c *Client) TestConnection(url, branch string, auth AuthConfig) error {- tmpDir, err := c.Clone(url, branch, auth)+func (c *Client) TestConnection(ctx context.Context, url, branch string, auth AuthConfig) error {+ if err := ctx.Err(); err != nil {+ return err+ }++ tmpDir, err := c.Clone(ctx, url, branch, auth)if err != nil {return err}@@ -438,7 +470,10 @@ func (c *Client) TestConnection(url, branch string, auth AuthConfig) error {}// FileExists checks if a file exists in the repository-func (c *Client) FileExists(repoPath, filePath string) bool {+func (c *Client) FileExists(ctx context.Context, repoPath, filePath string) bool {+ if err := ctx.Err(); err != nil {+ return false+ }if err := ValidatePath(repoPath, filePath); err != nil {return false}@@ -449,7 +484,10 @@ func (c *Client) FileExists(repoPath, filePath string) bool {}// ReadFile reads a file from the repository-func (c *Client) ReadFile(repoPath, filePath string) (string, error) {+func (c *Client) ReadFile(ctx context.Context, repoPath, filePath string) (string, error) {+ if err := ctx.Err(); err != nil {+ return "", err+ }if err := ValidatePath(repoPath, filePath); err != nil {return "", err}diff --git a/backend/internal/utils/http/client.go b/backend/internal/utils/http/client.goindex 21bd48f68..27966fca8 100644--- a/backend/internal/utils/http/client.go+++ b/backend/internal/utils/http/client.go@@ -18,3 +18,17 @@ func NewHTTPClient() *http.Client {Timeout: 10 * time.Second,}}++func NewHTTPClientWithTimeout(timeout time.Duration) *http.Client {+ transport := &http.Transport{+ Proxy: http.ProxyFromEnvironment,+ MaxIdleConns: 100,+ IdleConnTimeout: 90 * time.Second,+ TLSHandshakeTimeout: 10 * time.Second,+ ExpectContinueTimeout: 1 * time.Second,+ }+ return &http.Client{+ Transport: transport,+ Timeout: timeout,+ }+}diff --git a/backend/internal/utils/timeouts/timeouts.go b/backend/internal/utils/timeouts/timeouts.gonew file mode 100644index 000000000..3955a8cbd--- /dev/null+++ b/backend/internal/utils/timeouts/timeouts.go@@ -0,0 +1,26 @@+package timeouts++import (+ "context"+ "time"+)++const (+ DefaultDockerAPI = 30 * time.Second+ DefaultDockerImagePull = 10 * time.Minute+ DefaultGitOperation = 5 * time.Minute+ DefaultHTTPClient = 30 * time.Second+ DefaultRegistry = 30 * time.Second+ DefaultProxyRequest = 60 * time.Second+)++func GetDuration(settingSeconds int, defaultDuration time.Duration) time.Duration {+ if settingSeconds > 0 {+ return time.Duration(settingSeconds) * time.Second+ }+ return defaultDuration+}++func WithTimeout(ctx context.Context, settingSeconds int, defaultDuration time.Duration) (context.Context, context.CancelFunc) {+ return context.WithTimeout(ctx, GetDuration(settingSeconds, defaultDuration))+}diff --git a/frontend/messages/en.json b/frontend/messages/en.jsonindex a0c3ae099..1c1aa7aa6 100644--- a/frontend/messages/en.json+++ b/frontend/messages/en.json@@ -1028,6 +1028,23 @@"disk_usage_save": "Disk usage path updated successfully","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_description": "Configure operation timeouts for slow networks or hardware. All values are in seconds.",+ "timeouts_save": "Timeout settings updated successfully",+ "timeouts_save_failed": "Failed to update timeout settings",+ "docker_api_timeout": "Docker API Timeout",+ "docker_api_timeout_description": "Timeout for Docker list operations in seconds (default: 30)",+ "docker_image_pull_timeout": "Docker Image Pull Timeout",+ "docker_image_pull_timeout_description": "Timeout for Docker image pulls in seconds (default: 600 = 10 minutes)",+ "git_operation_timeout": "Git Operation Timeout",+ "git_operation_timeout_description": "Timeout for Git clone/fetch operations in seconds (default: 300 = 5 minutes)",+ "http_client_timeout": "HTTP Client Timeout",+ "http_client_timeout_description": "Default timeout for HTTP requests in seconds (default: 30)",+ "registry_timeout": "Registry Timeout",+ "registry_timeout_description": "Timeout for container registry operations in seconds (default: 30)",+ "proxy_request_timeout": "Proxy Request Timeout",+ "proxy_request_timeout_description": "Timeout for proxied requests in seconds (default: 60)","_comment_customize_overview": "=== CUSTOMIZATION - OVERVIEW ===","customize_title": "Customization","customize_subtitle": "Customize templates, registries, and configuration defaults",diff --git a/frontend/src/lib/types/settings.type.ts b/frontend/src/lib/types/settings.type.tsindex a4ed0f6ff..16993137a 100644--- a/frontend/src/lib/types/settings.type.ts+++ b/frontend/src/lib/types/settings.type.ts@@ -44,6 +44,13 @@ export type Settings = {glassEffectEnabled: boolean;+ dockerApiTimeout: number;+ dockerImagePullTimeout: number;+ gitOperationTimeout: number;+ httpClientTimeout: number;+ registryTimeout: number;+ proxyRequestTimeout: number;+registryCredentials: RegistryCredential[];templateRegistries: TemplateRegistryConfig[];};diff --git a/frontend/src/routes/(app)/settings/timeouts/+page.svelte b/frontend/src/routes/(app)/settings/timeouts/+page.sveltenew file mode 100644index 000000000..1b167871a--- /dev/null+++ b/frontend/src/routes/(app)/settings/timeouts/+page.svelte@@ -0,0 +1,192 @@+<script lang="ts">+ import { onMount } from 'svelte';+ import { z } from 'zod/v4';+ import settingsStore from '$lib/stores/config-store';+ import { m } from '$lib/paraglide/messages';+ import { SettingsPageLayout } from '$lib/layouts';+ import { Label } from '$lib/components/ui/label';+ import { ClockIcon } from '$lib/icons';+ import TextInputWithLabel from '$lib/components/form/text-input-with-label.svelte';+ import { createSettingsForm } from '$lib/utils/settings-form.util';++ let { data } = $props();++ const currentSettings = $derived($settingsStore || data.settings!);+ const isReadOnly = $derived.by(() => $settingsStore?.uiConfigDisabled);++ const formSchema = z.object({+ dockerApiTimeout: z.coerce.number().int().min(1).max(3600),+ dockerImagePullTimeout: z.coerce.number().int().min(30).max(7200),+ gitOperationTimeout: z.coerce.number().int().min(30).max(3600),+ httpClientTimeout: z.coerce.number().int().min(5).max(300),+ registryTimeout: z.coerce.number().int().min(5).max(300),+ proxyRequestTimeout: z.coerce.number().int().min(10).max(600)+ });++ let { formInputs, registerOnMount } = $derived(+ createSettingsForm({+ schema: formSchema,+ currentSettings,+ getCurrentSettings: () => $settingsStore || data.settings!,+ successMessage: m.timeouts_save()+ })+ );++ onMount(() => registerOnMount());+</script>++<SettingsPageLayout+ title={m.timeouts_settings()}+ description={m.timeouts_settings_description()}+ icon={ClockIcon}+ pageType="form"+ showReadOnlyTag={isReadOnly}+>+ {#snippet mainContent()}+ <fieldset disabled={isReadOnly} class="relative space-y-8">+ <!-- Docker Operations -->+ <div class="space-y-4">+ <h3 class="text-lg font-medium">Docker Operations</h3>+ <div class="bg-card rounded-lg border shadow-sm">+ <div class="space-y-6 p-6">+ <div class="grid gap-4 md:grid-cols-[1fr_1.5fr] md:gap-8">+ <div>+ <Label class="text-base">{m.docker_api_timeout()}</Label>+ <p class="text-muted-foreground mt-1 text-sm">+ {m.docker_api_timeout_description()}+ </p>+ </div>+ <div class="max-w-xs">+ <TextInputWithLabel+ bind:value={$formInputs.dockerApiTimeout.value}+ error={$formInputs.dockerApiTimeout.error}+ label={m.docker_api_timeout()}+ placeholder="30"+ helpText="Timeout in seconds (1-3600)"+ type="number"+ />+ </div>+ </div>++ <div class="border-t pt-6">+ <div class="grid gap-4 md:grid-cols-[1fr_1.5fr] md:gap-8">+ <div>+ <Label class="text-base">{m.docker_image_pull_timeout()}</Label>+ <p class="text-muted-foreground mt-1 text-sm">+ {m.docker_image_pull_timeout_description()}+ </p>+ </div>+ <div class="max-w-xs">+ <TextInputWithLabel+ bind:value={$formInputs.dockerImagePullTimeout.value}+ error={$formInputs.dockerImagePullTimeout.error}+ label={m.docker_image_pull_timeout()}+ placeholder="600"+ helpText="Timeout in seconds (30-7200)"+ type="number"+ />+ </div>+ </div>+ </div>+ </div>+ </div>+ </div>++ <!-- Git Operations -->+ <div class="space-y-4">+ <h3 class="text-lg font-medium">Git Operations</h3>+ <div class="bg-card rounded-lg border shadow-sm">+ <div class="space-y-6 p-6">+ <div class="grid gap-4 md:grid-cols-[1fr_1.5fr] md:gap-8">+ <div>+ <Label class="text-base">{m.git_operation_timeout()}</Label>+ <p class="text-muted-foreground mt-1 text-sm">+ {m.git_operation_timeout_description()}+ </p>+ </div>+ <div class="max-w-xs">+ <TextInputWithLabel+ bind:value={$formInputs.gitOperationTimeout.value}+ error={$formInputs.gitOperationTimeout.error}+ label={m.git_operation_timeout()}+ placeholder="300"+ helpText="Timeout in seconds (30-3600)"+ type="number"+ />+ </div>+ </div>+ </div>+ </div>+ </div>++ <!-- Network Operations -->+ <div class="space-y-4">+ <h3 class="text-lg font-medium">Network Operations</h3>+ <div class="bg-card rounded-lg border shadow-sm">+ <div class="space-y-6 p-6">+ <div class="grid gap-4 md:grid-cols-[1fr_1.5fr] md:gap-8">+ <div>+ <Label class="text-base">{m.http_client_timeout()}</Label>+ <p class="text-muted-foreground mt-1 text-sm">+ {m.http_client_timeout_description()}+ </p>+ </div>+ <div class="max-w-xs">+ <TextInputWithLabel+ bind:value={$formInputs.httpClientTimeout.value}+ error={$formInputs.httpClientTimeout.error}+ label={m.http_client_timeout()}+ placeholder="30"+ helpText="Timeout in seconds (5-300)"+ type="number"+ />+ </div>+ </div>++ <div class="border-t pt-6">+ <div class="grid gap-4 md:grid-cols-[1fr_1.5fr] md:gap-8">+ <div>+ <Label class="text-base">{m.registry_timeout()}</Label>+ <p class="text-muted-foreground mt-1 text-sm">+ {m.registry_timeout_description()}+ </p>+ </div>+ <div class="max-w-xs">+ <TextInputWithLabel+ bind:value={$formInputs.registryTimeout.value}+ error={$formInputs.registryTimeout.error}+ label={m.registry_timeout()}+ placeholder="30"+ helpText="Timeout in seconds (5-300)"+ type="number"+ />+ </div>+ </div>+ </div>++ <div class="border-t pt-6">+ <div class="grid gap-4 md:grid-cols-[1fr_1.5fr] md:gap-8">+ <div>+ <Label class="text-base">{m.proxy_request_timeout()}</Label>+ <p class="text-muted-foreground mt-1 text-sm">+ {m.proxy_request_timeout_description()}+ </p>+ </div>+ <div class="max-w-xs">+ <TextInputWithLabel+ bind:value={$formInputs.proxyRequestTimeout.value}+ error={$formInputs.proxyRequestTimeout.error}+ label={m.proxy_request_timeout()}+ placeholder="60"+ helpText="Timeout in seconds (10-600)"+ type="number"+ />+ </div>+ </div>+ </div>+ </div>+ </div>+ </div>+ </fieldset>+ {/snippet}+</SettingsPageLayout>diff --git a/frontend/src/routes/(app)/settings/timeouts/+page.ts b/frontend/src/routes/(app)/settings/timeouts/+page.tsnew file mode 100644index 000000000..eca96acce--- /dev/null+++ b/frontend/src/routes/(app)/settings/timeouts/+page.ts@@ -0,0 +1,12 @@+import type { PageLoad } from './$types';+import { settingsService } from '$lib/services/settings-service';++export const load: PageLoad = async () => {+ try {+ const settings = await settingsService.getSettings();+ return { settings };+ } catch (error) {+ console.error('Failed to load timeout settings:', error);+ throw error;+ }+};