mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5121] [Bug]: Telegram bot and panel synchronization #3599
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#3599
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 @Sadegh-Kalami on GitHub (Jun 9, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5121
Describe the bug
Whenever I modify client data on the Telegram bot, the panel doesn't update the modified setting, but in the background everything is working. It can cause race condition.
How to reproduce the problem
Expected behavior
No response
Actual behavior
No response
Relevant logs
Screenshots
No response
3x-ui version
3.2.7
Xray-core version
26.6.1
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu 24.04
Which parts of the panel are affected?
Frontend (UI / panel pages), Backend (API endpoints, login, settings), Subscription (share links / Clash / JSON), Statistics / traffic counters, Telegram bot
Browser (only if it is a UI bug)
any browsers
Is the panel behind a reverse proxy or CDN?
No — direct access
Before submitting
@github-actions[bot] commented on GitHub (Jun 9, 2026):
This is a confirmed race condition between two concurrent code paths that both write to the
client_trafficstable without coordinating with each other.Root cause
addClientTraffic(called by the traffic accounting cron job inweb/job/xray_traffic_job.go→web/service/inbound.go:2241) does a full-row save on a snapshot it took at the start of the tick:Telegram bot client-config changes (
limit_traffic_c→ResetClientTrafficLimitByEmail,reset_exp_c→ResetClientExpiryTimeByEmail,limit_ip_c→ResetClientIpLimitByEmail) callUpdateInboundClient→UpdateClientStat(web/service/inbound.go:2873), which writes specific columns (total,expiry_time,enable,reset) outside thesubmitTrafficWriteserializer.If the traffic job reads the snapshot before the bot writes, and the job's
tx.Savelands after the bot writes, it silently reverts the bot's change — settingtotal,expiry_time, andenableback to the values they had at the start of that traffic tick.What
submitTrafficWritedoes and doesn't protect: theweb/service/traffic_writer.goserializer covers all traffic-accumulation writes (AddTraffic,ResetClientTrafficByEmail, etc.) but notUpdateClientStat. That's the gap.Why it appears to "work in the background"
After the bot writes, xray restarts (
SetToNeedRestart) and picks up the new settings, so connections succeed for seconds or minutes — until the next traffic tick fires andtx.Savereverts theenable/total/expiry_timecolumns. The panel then reads the reverted DB row, which is why the change appears not to stick.Related issue
#5039 ("Telegram bot doesn't change expiration date") describes exactly the same race in the expiry path. The "message is not modified" Telegram warning in that report means
searchClientread the reverted row immediately after the bot wrote, confirming the job had already overwritten it.Workaround until fixed
UpdateClientStatpath but is unaffected in practice because the panel refresh is user-triggered and not racing a background saver on a tight loop.Fix direction
addClientTrafficshould use column-specificUpdates(e.g., incrementup/down, setlast_online) rather thantx.Saveon a stale full-row snapshot, orUpdateClientStatshould be routed throughsubmitTrafficWriteso it is serialized with the traffic job.