fix(server): keep only the requested tail while reading the access log

GetXrayLogs held one entry for every line of Xray's access log and cut
the list to the requested count only at EOF, so the panel's memory grew
with the file. Xray writes a line for every refused request, which puts
the file's size in the hands of anyone who can reach an inbound port,
and the periodic prune does not bound it between runs. A negative count
also panicked on the final slice.

Entries beyond the newest count are dropped while scanning, and count
is clamped to 1..10000 with 100 as the fallback, as GetAmneziaWGLogs
already does.
This commit is contained in:
MHSanaei
2026-11-01 00:31:59 +01:00
parent c3a32c8343
commit 776ca554bd
2 changed files with 115 additions and 6 deletions
+9 -5
View File
@@ -1482,7 +1482,10 @@ func (s *ServerService) GetXrayLogs(
Proxied
)
countInt, _ := strconv.Atoi(count)
countInt, err := strconv.Atoi(count)
if err != nil || countInt < 1 || countInt > 10000 {
countInt = 100
}
var entries []LogEntry
pathToAccessLog, err := xray.GetAccessLogPath()
@@ -1530,17 +1533,18 @@ func (s *ServerService) GetXrayLogs(
entry.Event = Proxied
}
// Anyone reaching an inbound port adds lines here, so only the newest
// countInt entries are kept while reading, not one per line of the file.
entries = append(entries, entry)
if len(entries) > countInt {
entries = entries[1:]
}
}
if err := scanner.Err(); err != nil {
return nil
}
if len(entries) > countInt {
entries = entries[len(entries)-countInt:]
}
return entries
}