fix(backend): fix memory leaks and resource issues in logs system
CI / build (push) Successful in 1m18s

- Fix Subscribe overwriting channel without closing old one (goroutine leak)
- Add context.Context to Stream() for cancellation support
- Add WebSocket read pump to detect dead clients (StreamLogs, StreamSteamCMDLogs, StreamRPTLogs)
- Use defer f.Close() pattern in StreamRPTLogs file handling
- Fix findLatestRPT nil dereference on failed os.Stat
- Optimize findLatestRPT to collect stat results before sorting
- Apply gofmt formatting to modlists.go, settings.go
This commit is contained in:
MrFastwind
2026-07-24 16:25:09 +02:00
parent 6f3175ac9a
commit 8bf163a931
7 changed files with 242 additions and 63 deletions
+56 -28
View File
@@ -7,20 +7,20 @@ import (
)
type updateSettingsInput struct {
IPPort *string `json:"ip_port"`
ServerParameters *string `json:"server_parameters"`
SteamBranch *string `json:"steam_branch"`
SteamUser *string `json:"steam_user"`
Platform *string `json:"platform"`
CBASettings *string `json:"cba_settings"`
AILevelPresets *string `json:"ai_level_presets"`
DifficultyPresets *string `json:"difficulty_presets"`
ActiveConfig *string `json:"active_config"`
ActiveModlist *string `json:"active_modlist"`
AutoUpdateOnStartup *bool `json:"auto_update_on_startup"`
AutoStartOnStartup *bool `json:"auto_start_on_startup"`
AutoUpdateModsOnStartup *bool `json:"auto_update_mods_on_startup"`
ScheduledUpdate *string `json:"scheduled_update"`
IPPort *string `json:"ip_port"`
ServerParameters *string `json:"server_parameters"`
SteamBranch *string `json:"steam_branch"`
SteamUser *string `json:"steam_user"`
Platform *string `json:"platform"`
CBASettings *string `json:"cba_settings"`
AILevelPresets *string `json:"ai_level_presets"`
DifficultyPresets *string `json:"difficulty_presets"`
ActiveConfig *string `json:"active_config"`
ActiveModlist *string `json:"active_modlist"`
AutoUpdateOnStartup *bool `json:"auto_update_on_startup"`
AutoStartOnStartup *bool `json:"auto_start_on_startup"`
AutoUpdateModsOnStartup *bool `json:"auto_update_mods_on_startup"`
ScheduledUpdate *string `json:"scheduled_update"`
}
func (h *Handler) GetSettings(c *gin.Context) {
@@ -45,20 +45,48 @@ func (h *Handler) UpdateSettings(c *gin.Context) {
return
}
if input.IPPort != nil { s.IPPort = *input.IPPort }
if input.ServerParameters != nil { s.ServerParameters = *input.ServerParameters }
if input.SteamBranch != nil { s.SteamBranch = *input.SteamBranch }
if input.SteamUser != nil { s.SteamUser = *input.SteamUser }
if input.Platform != nil { s.Platform = *input.Platform }
if input.CBASettings != nil { s.CBASettings = *input.CBASettings }
if input.AILevelPresets != nil { s.AILevelPresets = *input.AILevelPresets }
if input.DifficultyPresets != nil { s.DifficultyPresets = *input.DifficultyPresets }
if input.ActiveConfig != nil { s.ActiveConfig = *input.ActiveConfig }
if input.ActiveModlist != nil { s.ActiveModlist = *input.ActiveModlist }
if input.AutoUpdateOnStartup != nil { s.AutoUpdateOnStartup = *input.AutoUpdateOnStartup }
if input.AutoStartOnStartup != nil { s.AutoStartOnStartup = *input.AutoStartOnStartup }
if input.AutoUpdateModsOnStartup != nil { s.AutoUpdateModsOnStartup = *input.AutoUpdateModsOnStartup }
if input.ScheduledUpdate != nil { s.ScheduledUpdate = *input.ScheduledUpdate }
if input.IPPort != nil {
s.IPPort = *input.IPPort
}
if input.ServerParameters != nil {
s.ServerParameters = *input.ServerParameters
}
if input.SteamBranch != nil {
s.SteamBranch = *input.SteamBranch
}
if input.SteamUser != nil {
s.SteamUser = *input.SteamUser
}
if input.Platform != nil {
s.Platform = *input.Platform
}
if input.CBASettings != nil {
s.CBASettings = *input.CBASettings
}
if input.AILevelPresets != nil {
s.AILevelPresets = *input.AILevelPresets
}
if input.DifficultyPresets != nil {
s.DifficultyPresets = *input.DifficultyPresets
}
if input.ActiveConfig != nil {
s.ActiveConfig = *input.ActiveConfig
}
if input.ActiveModlist != nil {
s.ActiveModlist = *input.ActiveModlist
}
if input.AutoUpdateOnStartup != nil {
s.AutoUpdateOnStartup = *input.AutoUpdateOnStartup
}
if input.AutoStartOnStartup != nil {
s.AutoStartOnStartup = *input.AutoStartOnStartup
}
if input.AutoUpdateModsOnStartup != nil {
s.AutoUpdateModsOnStartup = *input.AutoUpdateModsOnStartup
}
if input.ScheduledUpdate != nil {
s.ScheduledUpdate = *input.ScheduledUpdate
}
if err := h.process.WriteUserconfigFiles(s); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "write userconfig: " + err.Error()})