mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6499] [MERGED] fix(tgbot): keep the add-client draft with the chat that owns it #6311
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#6311
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?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6499
Author: @BlindMaster24
Created: 9/13/2026
Status: ✅ Merged
Merged: 9/13/2026
Merged by: @MHSanaei
Base:
main← Head:fix/tgbot-per-chat-add-client-draft📝 Commits (2)
d913cc9fix(tgbot): keep the add-client draft with the chat that owns itda9a4f2fix(tgbot): take the wizard's draft lock only for the wizard📊 Changes
6 files changed (+374 additions, -150 deletions)
View changed files
📝
internal/web/service/tgbot/tgbot.go(+56 -18)📝
internal/web/service/tgbot/tgbot_client.go(+31 -31)➕
internal/web/service/tgbot/tgbot_client_draft_per_chat_test.go(+178 -0)📝
internal/web/service/tgbot/tgbot_draft_render_test.go(+16 -18)📝
internal/web/service/tgbot/tgbot_inbound.go(+3 -3)📝
internal/web/service/tgbot/tgbot_router.go(+90 -80)📄 Description
Summary
The add-client wizard now keeps one draft per chat instead of one package-level draft for the whole bot, so two admins adding a client at the same time cannot fill in each other's client.
Why
The wizard's state lived in package-level variables —
receiver_inbound_ID,receiver_inbound_IDs,client_Email,client_LimitIP,client_TotalGB,client_ExpiryTime,client_Enable,client_TgID,client_SubID,client_Comment,client_Reset(internal/web/service/tgbot/tgbot.go) — while its steps run on the ten-goroutine pool (messageWorkerPool = make(chan struct{}, 10), wired throughrunBotHandlerininternal/web/service/tgbot/tgbot_router.go). Two admins sharing the bot is the documented case: the bot serves every id inadminIds, and the wizard is the one flow that carries state between messages.What that produces:
SubmitAddClientthen builds the client from the shared values, so A's "Create" writes B's inbound, traffic limit and expiry — and the links the bot then sends back are for the wrong client.add_client_toggle_attachsplicesreceiver_inbound_IDsin place, which is a data race, not just a last-writer-wins mistake.User story: two operators run one panel and both use the Telegram bot (that is what
adminIdsis for). During a bulk client migration they each open Add Client and work through the card at the same time. Each ends up with a client built from a mixture of the two forms — and the share links they forward belong to a client whose limits neither of them chose.Type of change
Areas affected
How was this tested?
New
TestAddClientDraftIsPerChatdrives the real callback path (answerCallback→addClient→ the bot API) for two chats against anhttptestbot server, and reads the draft card that reaches each chat:add_client_to 1), chat B starts one (add_client_to 2). Each card must carry the email the wizard just generated for that chat.add_client_default_traffic_exp) with chat B's wizard already past its start. A's card must still show A's own email.With the per-chat keying reverted — one shared draft, the old behaviour — the test reddens exactly on the bug:
The whole
internal/web/service/tgbotpackage suite passes with the change, including the two existing tests that drive this wizard (TestClientDraftMessageRendersHTML,TestAddClientPromptsEscapeDraftValues, updated to seed the draft of the chat they use).go vetis clean for the package.Two things stated rather than glossed:
-racecannot run on this machine (it needs cgo and there is no C compiler), so CI'sracejob is what runs the detector over this. The behavioural test above needs no race detector to fail.Screenshots / recordings
N/A — no UI change.
Breaking changes
None for users.
BuildClientDraftMessage,SubmitAddClient,getInboundsAttachPickerandgetCommonClientButtonstake the chat's draft as an argument; all four are package-private and used only insideinternal/web/service/tgbot(checked with a repository-wide grep), so no other package is affected.Checklist
go build ./...and the test suite pass locally. (no C compiler here — CI verifies the CGo build)npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.