fix(sub): keep the salamander warning state one entry per inbound

genHysteriaLink remembered which salamander settings it had warned
about in a set keyed by the setting names themselves, which a node
chooses with no bound on length or number and the set never forgot,
and it logged the names verbatim into the in-memory log buffer. A node
renaming a setting on every poll grew the master's memory by twice the
name's size per subscription fetch until the process ran out.

The set is keyed by inbound id and holds a digest of the names, the
warning repeats only when that set changes, and it logs at most eight
names cut to 32 characters.
This commit is contained in:
MHSanaei
2026-11-01 00:45:21 +01:00
parent bebe1b911d
commit c2250dbe57
2 changed files with 46 additions and 3 deletions
+6 -3
View File
@@ -31,6 +31,8 @@ import (
"github.com/mhsanaei/3x-ui/v3/internal/xray"
)
// salamanderWarningSeen maps an inbound id to a digest of the setting names
// last warned about: a node picks the names, so the entry must stay fixed-size.
var salamanderWarningSeen sync.Map
// SubService provides business logic for generating subscription links and managing subscription data.
@@ -1610,9 +1612,10 @@ func (s *SubService) genHysteriaLink(inbound *model.Inbound, email string) strin
// packetSize rides its own URI fields; anything else still
// breaks standard clients and must warn even when gecko fires.
if extra := extraSalamanderKeys(settings, gecko != ""); len(extra) > 0 {
warningKey := fmt.Sprintf("%d:%v", inbound.Id, extra)
if _, loaded := salamanderWarningSeen.LoadOrStore(warningKey, struct{}{}); !loaded {
logger.Warningf("SubService - inbound %d: salamander settings %v cannot be expressed in a hysteria2 URI; standard clients will fail the handshake", inbound.Id, extra)
// Warn again when the set changes; log a bounded sample of the names.
digest := sha256.Sum256([]byte(strings.Join(extra, "\x00")))
if prev, _ := salamanderWarningSeen.Swap(inbound.Id, digest); prev != digest {
logger.Warningf("SubService - inbound %d: salamander settings %.32q cannot be expressed in a hysteria2 URI; standard clients will fail the handshake", inbound.Id, extra[:min(len(extra), 8)])
}
}
if params["obfs"] == "" {