[GH-ISSUE #5100] Resetting an inbound's traffic on the master does not propagate to slave nodes (reverts after sync) #3585

Closed
opened 2026-10-31 20:33:30 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @yukh975 on GitHub (Jun 8, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5100

Version

3.2.8 (also present on current main, commit 0d7b6872)

Describe the bug

When you reset traffic for a node-owned inbound from the master panel
(the inbound's "Reset Traffic", or "Reset All Traffics"), the master DB is zeroed
and the UI shows 0 for a moment — but the slave node's counters are never
reset. On the next node sync the master's value is overwritten back to the real
(non-reset) traffic, so after a page refresh the traffic reappears.

Workaround: log in to each node's own panel and reset the traffic there.

To Reproduce

  1. A master panel with at least one node (sub-panel) added, so the node's inbound
    appears in the master's Inbounds list with its traffic.
  2. On the master, click Reset Traffic on that node-owned inbound (or Reset
    All Traffics
    ).
  3. The value shows 0 briefly.
  4. Wait for the next node sync / refresh the page → the traffic is back to its
    previous value.

Expected behavior

Resetting a node-owned inbound's traffic from the master should also reset it on
the slave node — the same way the per-client traffic reset already does — so
the value stays at 0 after the next sync.

Root cause (pointers)

The inbound-level reset only updates the master DB; it does not propagate to
the node, so the next node sync re-imports the slave's (still non-zero) traffic:

  • InboundService.ResetInboundTraffic (web/service/inbound.go) — does only
    db.Model(model.Inbound{}).Where("id = ?", id).Updates({"up":0,"down":0}).
  • InboundService.resetAllTrafficsLocked (web/service/inbound.go) — same,
    DB-only.

By contrast, the client reset path does propagate to the node:

  • InboundService.resetClientTrafficLocked calls s.nodePushPlan(inbound) and
    logs "ResetClientTraffic: remote propagation to <node> failed" on error.

Suggested fix

Mirror the client path in ResetInboundTraffic / resetAllTrafficsLocked: for
node-owned inbounds (NodeID != 0) forward the reset to the slave via the same
nodePushPlan / remote mechanism, so the node zeroes its own counters and the
next sync no longer restores the old values.

Originally created by @yukh975 on GitHub (Jun 8, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5100 ### Version 3.2.8 (also present on current `main`, commit `0d7b6872`) ### Describe the bug When you reset traffic for a **node-owned inbound** from the **master** panel (the inbound's "Reset Traffic", or "Reset All Traffics"), the master DB is zeroed and the UI shows `0` for a moment — but the **slave node's** counters are never reset. On the next node sync the master's value is overwritten back to the real (non-reset) traffic, so after a page refresh the traffic reappears. Workaround: log in to each node's own panel and reset the traffic there. ### To Reproduce 1. A master panel with at least one node (sub-panel) added, so the node's inbound appears in the master's **Inbounds** list with its traffic. 2. On the master, click **Reset Traffic** on that node-owned inbound (or **Reset All Traffics**). 3. The value shows `0` briefly. 4. Wait for the next node sync / refresh the page → the traffic is back to its previous value. ### Expected behavior Resetting a node-owned inbound's traffic from the master should also reset it on the slave node — the same way the **per-client** traffic reset already does — so the value stays at `0` after the next sync. ### Root cause (pointers) The inbound-level reset only updates the **master** DB; it does not propagate to the node, so the next node sync re-imports the slave's (still non-zero) traffic: - `InboundService.ResetInboundTraffic` (`web/service/inbound.go`) — does only `db.Model(model.Inbound{}).Where("id = ?", id).Updates({"up":0,"down":0})`. - `InboundService.resetAllTrafficsLocked` (`web/service/inbound.go`) — same, DB-only. By contrast, the **client** reset path *does* propagate to the node: - `InboundService.resetClientTrafficLocked` calls `s.nodePushPlan(inbound)` and logs `"ResetClientTraffic: remote propagation to <node> failed"` on error. ### Suggested fix Mirror the client path in `ResetInboundTraffic` / `resetAllTrafficsLocked`: for node-owned inbounds (`NodeID != 0`) forward the reset to the slave via the same `nodePushPlan` / remote mechanism, so the node zeroes its own counters and the next sync no longer restores the old values.
bsakaguchi 2026-10-31 20:33:30 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jun 8, 2026):

Confirmed bug — root cause and fix path

Your analysis is spot-on. I verified the code on main (0d7b687).

What the code actually does

InboundService.ResetInboundTraffic (web/service/inbound.go:3017):

func (s *InboundService) ResetInboundTraffic(id int) error {
    return submitTrafficWrite(func() error {
        db := database.GetDB()
        return db.Model(model.Inbound{}).
            Where("id = ?", id).
            Updates(map[string]any{"up": 0, "down": 0}).Error
    })
}

Pure DB write on the master. No node propagation at all.

resetAllTrafficsLocked (web/service/inbound.go:3000): same — bulk DB update only, no node propagation.

resetClientTrafficLocked (web/service/inbound.go:2981), by contrast, does this after the DB write:

if inbound.NodeID \!= nil {
    if rt, rterr := s.runtimeFor(inbound); rterr == nil {
        if e := rt.ResetClientTraffic(context.Background(), inbound, clientEmail); e \!= nil {
            logger.Warning("ResetClientTraffic: remote propagation to", rt.Name(), "failed:", e)
        }
    }
}

Why the fix is straightforward

The Runtime interface (web/runtime/runtime.go:28) already defines ResetClientTraffic and ResetAllTraffics. The remote implementation (web/runtime/remote.go:391) calls the slave's REST API:

  • ResetClientTraffic → POST panel/api/clients/resetTraffic/<email>
  • ResetAllTraffics → POST panel/api/inbounds/resetAllTraffics

Critically, the slave panel already exposes a per-inbound reset endpoint:

POST panel/api/inbounds/:id/resetTraffic   // web/controller/inbound.go:75

So the necessary pieces already exist on both ends; the master just never calls the slave.

Scope of the bug

The same missing propagation also affects the periodic traffic reset job (web/job/periodic_traffic_reset_job.go:41) — inbounds with a configured reset period that belong to a node will silently revert on the next sync as well.

Fix outline

  1. Add ResetInboundTraffic(ctx context.Context, ib *model.Inbound) error to the Runtime interface in web/runtime/runtime.go.
  2. Implement it in web/runtime/remote.go as a call to POST panel/api/inbounds/<ib.Id>/resetTraffic (same pattern as the existing ResetClientTraffic).
  3. Add a no-op stub in web/runtime/local.go (like the existing ResetAllTraffics stub there).
  4. In InboundService.ResetInboundTraffic (web/service/inbound.go:3017): after the DB write, load the inbound, check NodeID \!= nil, get the runtime via s.runtimeFor(inbound), and call rt.ResetInboundTraffic(...).
  5. In resetAllTrafficsLocked (web/service/inbound.go:3000): iterate over node-owned inbounds and call rt.ResetInboundTraffic(...) per node — or call rt.ResetAllTraffics(ctx) once per distinct node to batch it.

PRs are welcome if you'd like to contribute the fix!

<!-- gh-comment-id:4654194227 --> @github-actions[bot] commented on GitHub (Jun 8, 2026): ## Confirmed bug — root cause and fix path Your analysis is spot-on. I verified the code on `main` (`0d7b687`). ### What the code actually does **`InboundService.ResetInboundTraffic`** (`web/service/inbound.go:3017`): ```go func (s *InboundService) ResetInboundTraffic(id int) error { return submitTrafficWrite(func() error { db := database.GetDB() return db.Model(model.Inbound{}). Where("id = ?", id). Updates(map[string]any{"up": 0, "down": 0}).Error }) } ``` Pure DB write on the master. No node propagation at all. **`resetAllTrafficsLocked`** (`web/service/inbound.go:3000`): same — bulk DB update only, no node propagation. **`resetClientTrafficLocked`** (`web/service/inbound.go:2981`), by contrast, does this after the DB write: ```go if inbound.NodeID \!= nil { if rt, rterr := s.runtimeFor(inbound); rterr == nil { if e := rt.ResetClientTraffic(context.Background(), inbound, clientEmail); e \!= nil { logger.Warning("ResetClientTraffic: remote propagation to", rt.Name(), "failed:", e) } } } ``` ### Why the fix is straightforward The `Runtime` interface (`web/runtime/runtime.go:28`) already defines `ResetClientTraffic` and `ResetAllTraffics`. The remote implementation (`web/runtime/remote.go:391`) calls the slave's REST API: - `ResetClientTraffic` → `POST panel/api/clients/resetTraffic/<email>` - `ResetAllTraffics` → `POST panel/api/inbounds/resetAllTraffics` Critically, the slave panel **already exposes** a per-inbound reset endpoint: ``` POST panel/api/inbounds/:id/resetTraffic // web/controller/inbound.go:75 ``` So the necessary pieces already exist on both ends; the master just never calls the slave. ### Scope of the bug The same missing propagation also affects the **periodic traffic reset job** (`web/job/periodic_traffic_reset_job.go:41`) — inbounds with a configured reset period that belong to a node will silently revert on the next sync as well. ### Fix outline 1. Add `ResetInboundTraffic(ctx context.Context, ib *model.Inbound) error` to the `Runtime` interface in `web/runtime/runtime.go`. 2. Implement it in `web/runtime/remote.go` as a call to `POST panel/api/inbounds/<ib.Id>/resetTraffic` (same pattern as the existing `ResetClientTraffic`). 3. Add a no-op stub in `web/runtime/local.go` (like the existing `ResetAllTraffics` stub there). 4. In `InboundService.ResetInboundTraffic` (`web/service/inbound.go:3017`): after the DB write, load the inbound, check `NodeID \!= nil`, get the runtime via `s.runtimeFor(inbound)`, and call `rt.ResetInboundTraffic(...)`. 5. In `resetAllTrafficsLocked` (`web/service/inbound.go:3000`): iterate over node-owned inbounds and call `rt.ResetInboundTraffic(...)` per node — or call `rt.ResetAllTraffics(ctx)` once per distinct node to batch it. PRs are welcome if you'd like to contribute the fix\!
Author
Owner

@rqzbeh commented on GitHub (Jun 8, 2026):

Fixed in:
https://github.com/MHSanaei/3x-ui/pull/5103

<!-- gh-comment-id:4654337373 --> @rqzbeh commented on GitHub (Jun 8, 2026): Fixed in: https://github.com/MHSanaei/3x-ui/pull/5103
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#3585
No description provided.