mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6744] Telegram bot bakes in panel-egress SOCKS proxy URL once at startup, racing Xray's own (re)start #4494
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#4494
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 @ARBlazeAG on GitHub (Oct 5, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6744
Описание / Description
Tgbot.Start()resolves the panel egress SOCKS bridge (PanelEgressProxyURL()) once, at bot startup, and bakes the resultingsocks5://127.0.0.1:<port>URL into the long-lived Telegram API client (telego):https://github.com/MHSanaei/3x-ui/blob/main/internal/web/service/tgbot/tgbot.go#L340-L352
On every x-ui process start,
Tgbot.Start()("Telegram bot receiver started") runs a couple of seconds before Xray has actually finished (re)binding the dynamically-injectedpanel-egressSOCKS inbound (internal/web/service/xray.go,injectPanelEgress, base port 62790). IfPanelEgressProxyURL()is called in that narrow window, two outcomes are both broken in slightly different ways:proc.IsRunning()is true andGetConfig()already contains thepanel-egressinbound entry (the Go-side struct was updated before the actual OS-level listener came up) → the bot bakes in a port that isn't actually accepting connections yet → immediateconnect: connection refusedonsetMyCommands/getUpdates.Contrast with
discord/gateway.go, which stores the resolver itself rather than a resolved value and calls it fresh on every connection attempt:https://github.com/MHSanaei/3x-ui/blob/main/internal/web/service/discord/gateway.go#L101
https://github.com/MHSanaei/3x-ui/blob/main/internal/web/service/discord/gateway.go#L226
Discord's Gateway client self-heals on its own reconnect loop (we see it log
panel outbound [ direct ] is set but Xray is not running, using a direct connectionand recover automatically within seconds). The Telegram bot has no equivalent reconnect-driven re-resolution path, so a bad snapshot taken at the wrong instant is permanent until someone manually restarts the bot.Repro
Reliably hit on every x-ui restart when a
panelOutboundis configured (even justdirect, sinceinjectPanelEgressonly checks that the target tag resolves, not that it does anything useful):followed shortly after by a log line proving Xray itself was mid-restart at that exact moment:
x-ui dev channel, confirmed on
dev+49fbcdc0, bundled Xray-core pinned at 26.6.27 (unrelated to the bug — same race happens before the version pin even runs).Suggested fix
Give
Tgbotthe same shapeGatewayClientalready uses: storePanelEgressProxyURLas afunc() stringand call it right before eachNewBot/API-client (re)construction inside the bot's own reconnect/retry loop, instead of resolving once inStart(). Alternatively, hook bot restart into whatever event already fires when Xray finishes a (re)start, so the bot picks up a fresh egress URL without a full x-ui restart.Environment
-getApiToken-based external pin tooling, unrelated to this bug)x-ui.service