[PR #4917] [MERGED] fix: prevent stale node snapshot from re-enabling a panel-disabled client #5747

Closed
opened 2026-11-02 04:03:47 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/4917
Author: @younesvatan78
Created: 6/4/2026
Status: ✅ Merged
Merged: 6/4/2026
Merged by: @MHSanaei

Base: main ← Head: fix/node-snapshot-re-enables-disabled-client


📝 Commits (2)

  • d606f9e fix(node-traffic): prevent stale node snapshot from re-enabling disabled client
  • adfb4dd Merge branch 'main' into fix/node-snapshot-re-enables-disabled-client

📊 Changes

1 file changed (+8 additions, -1 deletions)

View changed files

📝 web/service/inbound.go (+8 -1)

📄 Description

Problem

When a remote node syncs traffic back to the panel (setRemoteTrafficLocked), the SQL update unconditionally overwrites client_traffics.enable with the value from the node snapshot (cs.Enable).

If a snapshot carrying enable=true arrives after the central panel has already set enable=false (because the client hit their traffic limit), it silently re-enables the client. The client then keeps consuming traffic until the next disable cycle catches up — in practice 2–3× their allotted quota.

This was confirmed in production: users with a 10 GB limit were only disabled at 20–25 GB.

Root cause

// Before — node snapshot can overwrite a panel-side disable:
SET up = up + ?, down = down + ?, enable = ?, ...

Fix

Replace the unconditional SET enable = ? with a CASE expression that only allows a node snapshot to disable a client (1 → 0), never to re-enable one (0 → 1). The central panel remains the sole authority for turning a client back on.

enableExpr := "CASE WHEN ? = 0 THEN 0 ELSE enable END"
// SET ... enable = CASE WHEN ? = 0 THEN 0 ELSE enable END ...

Test

  1. Create a client with a small traffic limit on an inbound served by a remote node.
  2. Let the client reach the limit → panel sets enable=false.
  3. Trigger a node traffic sync (within 5 s).
  4. Before fix: client is re-enabled and can keep using traffic.
  5. After fix: enable stays false regardless of what the node snapshot says.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/4917 **Author:** [@younesvatan78](https://github.com/younesvatan78) **Created:** 6/4/2026 **Status:** ✅ Merged **Merged:** 6/4/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/node-snapshot-re-enables-disabled-client` --- ### 📝 Commits (2) - [`d606f9e`](https://github.com/MHSanaei/3x-ui/commit/d606f9eef3495b4393bd2cb78df957e02ed3f89d) fix(node-traffic): prevent stale node snapshot from re-enabling disabled client - [`adfb4dd`](https://github.com/MHSanaei/3x-ui/commit/adfb4dd1ef53f230d66d1d64c9176af0542bb488) Merge branch 'main' into fix/node-snapshot-re-enables-disabled-client ### 📊 Changes **1 file changed** (+8 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `web/service/inbound.go` (+8 -1) </details> ### 📄 Description ## Problem When a remote node syncs traffic back to the panel (`setRemoteTrafficLocked`), the SQL update unconditionally overwrites `client_traffics.enable` with the value from the node snapshot (`cs.Enable`). If a snapshot carrying `enable=true` arrives **after** the central panel has already set `enable=false` (because the client hit their traffic limit), it silently re-enables the client. The client then keeps consuming traffic until the next disable cycle catches up — in practice 2–3× their allotted quota. This was confirmed in production: users with a 10 GB limit were only disabled at 20–25 GB. ## Root cause ```go // Before — node snapshot can overwrite a panel-side disable: SET up = up + ?, down = down + ?, enable = ?, ... ``` ## Fix Replace the unconditional `SET enable = ?` with a `CASE` expression that only allows a node snapshot to **disable** a client (1 → 0), never to **re-enable** one (0 → 1). The central panel remains the sole authority for turning a client back on. ```go enableExpr := "CASE WHEN ? = 0 THEN 0 ELSE enable END" // SET ... enable = CASE WHEN ? = 0 THEN 0 ELSE enable END ... ``` ## Test 1. Create a client with a small traffic limit on an inbound served by a remote node. 2. Let the client reach the limit → panel sets `enable=false`. 3. Trigger a node traffic sync (within 5 s). 4. **Before fix**: client is re-enabled and can keep using traffic. 5. **After fix**: `enable` stays `false` regardless of what the node snapshot says. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:03:47 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5747
No description provided.