fix(limit-ip): leave a reverse client out of the temporary disconnect (#6553)

* fix(limit-ip): leave a reverse client out of the temporary disconnect

The LIMIT_IP cycle removes the client and adds it back 100 ms later. For a vless
client carrying a reverse config that is not reversible: RemoveUser calls
RemoveReverse and deletes the client's outbound handler, while the account added
back is built without the reverse field, so the tunnel stays down until Xray
restarts and the core's forward-proxy guard for that client no longer fires
(proxy/vless/inbound/inbound.go:245 and :542-544 at the pinned core). The cycle
now skips such a client and says so, instead of trading a limit violation for a
tunnel that needs a restart to come back.

TestDisconnectClientTemporarilySkipsReverseClient fails without this -- watched
red, the client is removed and re-added -- and asserts the skip is logged rather
than silent.

* style(limit-ip): keep the reverse-client comment within the 2-line cap

The block explaining why a reverse client is skipped was three lines, against
the rule this repo sets for committed Go comments; the same why fits in two.
This commit is contained in:
BlindMaster24
2026-09-15 16:57:23 +03:00
committed by GitHub
parent d440c2b932
commit d9c7c76fb0
2 changed files with 44 additions and 2 deletions
+11 -2
View File
@@ -627,11 +627,13 @@ func (j *CheckClientIpJob) disconnectClientTemporarily(inbound *model.Inbound, c
// Find the client config
var clientConfig map[string]any
var reverseClient bool
for _, client := range clients {
if client.Email == clientEmail {
// Convert client to map for API
clientBytes, _ := json.Marshal(client)
_ = json.Unmarshal(clientBytes, &clientConfig)
reverseClient = client.Reverse != nil
break
}
}
@@ -651,6 +653,13 @@ func (j *CheckClientIpJob) disconnectClientTemporarily(inbound *model.Inbound, c
return
}
// RemoveUser drops a reverse client's outbound handler and the re-add below
// cannot restore it, so its tunnel would stay down until Xray restarts.
if reverseClient {
logger.Warningf("[LIMIT_IP] Not disconnecting %s: its reverse proxy config does not survive a temporary removal", clientEmail)
return
}
// For Shadowsocks, ensure the required "cipher" field is present by
// reading it from the inbound settings (e.g., settings["method"]).
if string(inbound.Protocol) == "shadowsocks" {
@@ -664,8 +673,8 @@ func (j *CheckClientIpJob) disconnectClientTemporarily(inbound *model.Inbound, c
}
}
// The core's RemoveUser clears its validator, so a session already up keeps
// running -- except vless, where it also drops a reverse handler.
// The core's RemoveUser clears its validator: a session already up keeps
// running, except a reverse vless client, which is skipped above.
err = xrayAPI.RemoveUser(inbound.Tag, clientEmail)
if err != nil {
logger.Warningf("[LIMIT_IP] Failed to remove user %s: %v", clientEmail, err)