mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #7029] [MERGED] fix: panel restart left the panel unreachable for up to a minute #6586
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#6586
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/7029
Author: @Plus98ir
Created: 10/30/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @MHSanaei
Base:
main← Head:fix/panel-restart-hang📝 Commits (3)
fb0507dfix(jobs): stop the CPU alarm job from blocking panel restarts for a minute90f5ccffix(tgbot): end in-flight Telegram calls when the bot stops5ded2a7fix(jobs): keep iowait out of the CPU alarm's busy share📊 Changes
8 files changed (+304 additions, -42 deletions)
View changed files
➕
internal/util/sys/cpu_times.go(+36 -0)📝
internal/web/job/check_cpu_usage.go(+21 -8)➕
internal/web/job/check_cpu_usage_test.go(+104 -0)📝
internal/web/service/server.go(+2 -26)➕
internal/web/service/tgbot/stoppable_caller.go(+43 -0)➕
internal/web/service/tgbot/stoppable_caller_test.go(+68 -0)📝
internal/web/service/tgbot/tgbot.go(+26 -5)📝
internal/web/web.go(+4 -3)📄 Description
Problem
Restarting the panel from Settings left it unreachable (HTTP 502 behind nginx) for anywhere from a few seconds to a minute. On a live server the outages measured 4s, 19s and 45s. On a server where Telegram is unreachable it gets worse.
stop()closes the HTTP listener first and then waits for background work. Two parts of that work could block for a long time:CheckCpuJobsampled withcpu.Percent(1*time.Minute). Each run blocked for its full@every 1mperiod, so the job was nearly always running, andcron.Stop()waits for running jobs. This alone causes a 0–60s outage on every restart, Telegram or not.bus.Stop()waited for the Telegram notifier's in-flightsendMessage(~30s);tgbot.StartrangetMe+setMyCommandsinline (~60s) on the signal loop, so the sub server started late and a second restart request sat unhandled.Fix
CheckCpuJobkeeps the previouscpu.Timessample and reports the busy share since its last run. That is still a one-minute average, but nothing blocks. The delta formula moves tosys.CPUBusyPercent, which the status page's gopsutil fallback now shares (it had the same formula inline).stoppableCallerthat returns as soon asStopBotcloses that bot's stop channel, or as soon as the call's context ends. The bot is now stopped before the event bus, and the screen-art/commands warm-up runs in the background.Verification
stop()blocked first oncron.Stop()(inCheckCpuJob.Run), then onbus.Stop()(inliveNotice → SendMessage).TestCheckCpuJobRunDoesNotBlockForTheSamplePeriod: red on the old job, still blocking after 5s.TestCheckCpuJobPublishesUsageSinceThePreviousRun: red with the baseline guard removed (reports 1.5% instead of 75%).TestStopBotEndsInFlightTelegramCall: red with the channel close removed (getMestill blocked 2s afterStopBot).go test -shuffle=on ./internal/...green,-racegreen on the changed packages,golangci-lint0 issues.The stop ordering change in
web.goand the background warm-up are wiring only. No unit test reaches them; the restart timing above is what demonstrates them.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
[PR #7029] fix: panel restart left the panel unreachable for up to a minuteto [PR #7029] [MERGED] fix: panel restart left the panel unreachable for up to a minute