mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #4921] مشکل محاسبه ترافیک #3439
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#3439
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @libea18 on GitHub (Jun 4, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4921
Describe the bug
مشکلی که هست:
اگر اینباند اول روی سرور مادر باشه و اینباند دوم یک نود باشه
ما بیایم کلاینت اد کنیم، موقع اد کردن کلاینت جدید، اگه attach inbound رو اول نود انتخاب کنیم بعد اینباند خود سرور، ترافیک مصرفی کلاینت روی کانفیگ سرور مادر حساب نمیشه و جلو نمیره ولی ترافیک کانفیگ نود حساب میشه.
حالا اگه موقع اتچ، اول بیایم اینباند اولی(که روی خود سرور هست) رو انتخاب کنیم، بعد اینباند نود رو، ترافیک هردو رو درست حساب میکنه.
روی آخرین نسخه 3.2.7 تست شده
اینم اضافه کنم توی حالتی که ترافیک محاسبه نمیشه، کلاینت آنلاین میخورها، ولی ترافیک جلو نمیره
اگه به کانفیگ سرور نود وصل شم توی همون ساب، درجا ترافیک نود رو میزنه و حساب میکنه.
(این در حالتیه که اول سرور نود انتخاب شده باشه توی اتچ)
How to reproduce the problem
1-clients
2-add client
3-attach inbound
Expected behavior
No response
Actual behavior
No response
Relevant logs
Screenshots
No response
3x-ui version
3.2.7
Xray-core version
No response
How did you install 3x-ui?
install.sh script
Operating system
ubuntu24.04
Which parts of the panel are affected?
No response
Browser (only if it is a UI bug)
No response
Is the panel behind a reverse proxy or CDN?
None
Before submitting
@mitrios-hub commented on GitHub (Jun 4, 2026):
I wrote about this issue yesterday... Client using tunnels but traffic is zero and client is offline.
In some cases user can be online, but...
@github-actions[bot] commented on GitHub (Jun 4, 2026):
باگ تایید شده است — علت اصلی آن در کد پیدا شد.
علت باگ
در
web/service/inbound.go، تابعAddClientStat(خط ۲۳۹۹) یک ردیفClientTrafficدر دیتابیس میسازد که هم کلاینت و هم ترافیک مصرفی او را نگه میدارد. این ردیف روی فیلدemailیکتا (UNIQUE) است. اگر هنگام آتچ کردن، کلاینت به چند اینباند اضافه شود، فقط اولین اینباند انتخابشده این ردیف را میسازد؛ برای اینباندهای بعدی کد زیر اجرا میشود:یعنی اگر ایمیل از قبل وجود داشته باشد، هیچ کاری انجام نمیشود و
InboundIdردیف موجود همان اینباند اول باقی میماند.سپس در تابع
addClientTraffic(خط ۱۸۳۱)، موقع ثبت ترافیک دریافتی از Xray، فقط ردیفهایی پردازش میشوند که متعلق به نود نباشند:نتیجه:
InboundIdردیف = شناسه نود → در کوئری فوق فیلتر میشود → ترافیک سرور مادر ثبت نمیشود.InboundIdردیف = شناسه اینباند سرور اصلی → در کوئری گنجانده میشود → ترافیک هر دو درست حساب میشود.این دقیقاً همان رفتاری است که گزارش دادهاید.
راهحل موقت (تا رفع باگ)
هنگام اضافه کردن کلاینت با «Attach Inbound»، ابتدا اینباند سرور مادر را انتخاب کنید و بعد اینباند نود را. همانطور که خودتان هم متوجه شدهاید، این ترتیب مشکل را دور میزند.
فایلهای مرتبط برای رفع باگ
web/service/inbound.goAddClientStat— باید هنگام conflict،InboundIdرا به سمت اینباند سرور مادر بهروز کندweb/service/inbound.goaddClientTraffic— کوئری باید ردیفهایی باinbound_idاشتباه را هم پوشش دهدمشکلات مشابه قبلاً در #4712 و #4725 هم گزارش شده بودند که با همین منطق
OnConflictمرتبط است.@libea18 commented on GitHub (Jun 4, 2026):
برای من کلاینت انلاین میشود وقتی به کانفیگ سرور مادر وصل میشه ولی ترافیک اپدیت نمیشه. به محض وصل شدن به کانفیگ نود ترافیک جلو میره (ولی ترافیک مصرفی قبلی اپدیت نمیشه)
تنها در صورتی درست میشه که اول اینباند سرور مادر رو اتچ کنم بعد سرور نود . ( حتی با ادیت کردن کلاینت درست نمیشه و تنها راهش اد کردن کلاینت جدیده)
@bjerfan commented on GitHub (Jun 4, 2026):
واسه منم همینطور هست با حذف کلی نود هم مشکل حل نمیشه متاسفانه
@MHSanaei commented on GitHub (Jun 4, 2026):
Fixed in
e0845626.Root cause:
client_trafficsis keyed by email — one shared row per client across every inbound it is attached to. The local traffic updater filtered withinbound_id NOT IN (node inbounds), so when a client was attached to both a node inbound and the mother inbound and the node inbound was attached first, the shared row carried the node inbound's id (AddClientStatusesOnConflict DoNothingand never refreshes it). The local xray's traffic for that client was then dropped entirely — the client appeared online but its usage stayed at zero. Attaching the mother inbound first worked around it, exactly as reported.Fix: match purely by email. The reported emails come only from the local xray (which only knows local-attached clients), so the query stays correctly scoped, and this also repairs already-broken rows that re-adding the client previously worked around.
Verified with a Go unit test plus a Docker end-to-end run (repointed a client's shared row at a node inbound, drove real traffic through the mother inbound, confirmed the row accumulated).