Discard OOM drafts written by previous app versions

This commit is contained in:
世界
2026-08-30 17:41:47 +08:00
parent 103e266ebc
commit 3f986d584e
5 changed files with 28 additions and 5 deletions
+2
View File
@@ -6,6 +6,7 @@ import (
"path/filepath"
"syscall"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/experimental/libbox"
"github.com/sagernet/sing-box/log"
E "github.com/sagernet/sing/common/exceptions"
@@ -60,6 +61,7 @@ func prepareWorkingDirectory() error {
WorkingPath: workingDirectory,
TempPath: workingDirectory,
CrashReportSource: "Daemon",
AppVersion: C.Version,
})
if err != nil {
return err
+2
View File
@@ -10,6 +10,7 @@ import (
"sync"
"github.com/sagernet/sing-box/adapter"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/daemon"
"github.com/sagernet/sing-box/experimental/libbox"
"github.com/sagernet/sing-box/include"
@@ -194,6 +195,7 @@ func (d *Daemon) configureWorkingDirectoryLocked(directory string) error {
WorkingPath: directory,
TempPath: directory,
CrashReportSource: "Daemon",
AppVersion: C.Version,
})
if err != nil {
return err
+11
View File
@@ -357,6 +357,17 @@ func promoteOOMDraftAt(workingPath string) {
if err != nil || !info.IsDir() {
return
}
metadataContent, err := os.ReadFile(filepath.Join(draftPath, "metadata.json"))
if err != nil {
os.RemoveAll(draftPath)
return
}
var draftMetadata reportMetadata
err = json.Unmarshal(metadataContent, &draftMetadata)
if err != nil || draftMetadata.AppVersion != sAppVersion || draftMetadata.AppMarketingVersion != sAppMarketingVersion {
os.RemoveAll(draftPath)
return
}
reportsDir := filepath.Join(workingPath, "oom_reports")
initReportDir(reportsDir)
destPath, err := nextAvailableReportPath(reportsDir, info.ModTime().UTC())
+7 -5
View File
@@ -34,11 +34,13 @@ func baseReportMetadata() reportMetadata {
processName = ""
}
return reportMetadata{
Source: sCrashReportSource,
ProcessName: processName,
ProcessPath: processPath,
CoreVersion: C.Version,
GoVersion: GoVersion(),
Source: sCrashReportSource,
ProcessName: processName,
ProcessPath: processPath,
AppVersion: sAppVersion,
AppMarketingVersion: sAppMarketingVersion,
CoreVersion: C.Version,
GoVersion: GoVersion(),
}
}
+6
View File
@@ -31,6 +31,8 @@ var (
sLogMaxLines int
sDebug bool
sCrashReportSource string
sAppVersion string
sAppMarketingVersion string
sOOMKillerEnabled bool
sOOMKillerDisabled bool
sOOMMemoryLimit int64
@@ -52,6 +54,8 @@ type SetupOptions struct {
LogMaxLines int
Debug bool
CrashReportSource string
AppVersion string
AppMarketingVersion string
OomKillerEnabled bool
OomKillerDisabled bool
OomMemoryLimit int64
@@ -75,6 +79,8 @@ func applySetupOptions(options *SetupOptions) {
sLogMaxLines = options.LogMaxLines
sDebug = options.Debug
sCrashReportSource = options.CrashReportSource
sAppVersion = options.AppVersion
sAppMarketingVersion = options.AppMarketingVersion
ReloadSetupOptions(options)
}