mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6442] [MERGED] fix(tgbot): handle deleted inbounds on stale get_clients_for_* taps #6269
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#6269
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/6442
Author: @BlindMaster24
Created: 9/9/2026
Status: ✅ Merged
Merged: 9/10/2026
Merged by: @MHSanaei
Base:
main← Head:fix/tgbot-stale-button-panic📝 Commits (2)
c3fce6dfix(tgbot): close stale-inbound TOCTOU and contain handler panics0ffa841Merge branch 'main' into fix/tgbot-stale-button-panic📊 Changes
3 files changed (+176 additions, -43 deletions)
View changed files
📝
internal/web/service/tgbot/tgbot_inbound.go(+1 -6)📝
internal/web/service/tgbot/tgbot_router.go(+47 -37)➕
internal/web/service/tgbot/tgbot_stale_button_test.go(+128 -0)📄 Description
Summary
Stale
get_clients_for_sub/get_clients_for_individual/get_clients_for_qrinline-keyboard taps no longer crash the panel when the inbound is deleted in the window between the callback's twoGetInboundreads.Why
The three
get_clients_for_*callback cases fetched the inbound a second time with the error discarded:The first lookup (inside
getInboundClientsFor) already guarded a missing inbound; the panic needed the TOCTOU window between the two reads — the row vanishing (delete + concurrent tap, or a transient DB failure) between keyboard build andRemarkderef. BecauseanswerCallbackruns on a bare goroutine with norecover(), that panic killed the entire panel process, not just the bot.What changed
getInboundClientsFornow receives the*model.Inboundrow instead of re-reading the DB by ID; the between-reads window is removed rather than guarded. It is called from exactly one place, so the signature change breaks no other caller.chooseInboundClienthelper — fetches the inbound once, logs the failure (logger.Warning— a sick DB and a deleted inbound no longer look identical to an operator), answers agetInboundsFailedcallback, and builds the keyboard. The three duplicated case bodies collapse to a one-liner each.recover()barrier on all three handler paths — commands and callbacks run throughrunBotHandler(worker slot +recoverBotPanic), and theth.AnyMessage()free-text state machine (which runs inline on telego's dispatch goroutine, with no library-side recovery in telego v1.12.1) defersrecoverBotPanicdirectly. No bot handler panic can take down the process; it logs vialogger.Errorinstead.Type of change
Areas affected
How was this tested?
TestChooseInboundClientStaleInbound— driveschooseInboundClientagainst a test DB where inbound 42 does not exist, and assertsanswerCallbackQuerywas called exactly once (the error answer) via a counting mock Telegram API. Removing the guard fails the test with the nil panic itself; dropping only thesendCallbackAnswerTgBotcall fails the count assertion.TestGetInboundClientsForUsesProvidedInbound— pins that the keyboard builder consumes the caller-provided row (a reintroduced second DB read reopens the stale-row window). Asserts the built keyboard button text.TestRunBotHandlerRecoversPanic— asserts a panicking handler is contained byrunBotHandler; the panic escapes and fails the test without therecover().tgbot_send_test.go(httptest+telego.WithAPIServer), throwaway SQLite viadatabase.InitDB(t.TempDir()), std-lib only. gofmt-clean.go test ./...requires GCC (CGo/SQLite) which is available on CI; the local Windows box has no C compiler.Screenshots / recordings
N/A
Breaking changes
None — the happy path is unchanged; only the stale-tap path changed from a potential process crash to an answered error callback, and handler panics are now logged instead of fatal.
Checklist
go build ./...and the test suite pass locally. (requires GCC/MinGW — CI will verify)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.