mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #7089] fix(backup): give up on a pg_dump that does not finish within an hour #6643
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#6643
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/7089
Author: @Dv2Corn
Created: 11/6/2026
Status: 🔄 Open
Base:
main← Head:fix/pg-dump-timeout📝 Commits (1)
bbbb4fdfix(backup): give up on a pg_dump that does not finish within an hour📊 Changes
2 files changed (+50 additions, -1 deletions)
View changed files
📝
internal/web/service/server.go(+14 -1)➕
internal/web/service/server_pg_dump_test.go(+36 -0)📄 Description
Summary
On a PostgreSQL install,
pg_dumpnow runs under a one-hour deadline. A server that accepts the connection and then stops answering no longer hangs the database download and the scheduled Telegram and Discord backups forever; the caller gets a clear error instead.Why
exportPostgresDBstartspg_dumpwithcontext.Background()(server.go#L2033), so nothing ever stops it. It is reached throughGetDb()(server.go#L1638-L1641) from:GetDb()takes no context, so it does not reachpg_dump.If PostgreSQL accepts the connection and then stalls (a lock that is never released, a half-dead network path, a server under heavy I/O pressure),
pg_dumpwaits forever and so does its caller. The cron scheduler wraps every job inSkipIfStillRunning(web.go#L548), so the stuck Telegram or Discord notify job (web.go#L406, #L419) makes every later run of it be skipped, with no log line (cron.DiscardLogger). The admin stops getting both the periodic reports and the backups and is never told why.What changes:
pg_dumpruns undercontext.WithTimeoutwithpgDumpTimeout(one hour, generous for any panel database), andcmd.WaitDelayof 10 seconds so a killedpg_dumpcannot keepRunwaiting on its output pipes.pg_dump did not finish within 1h0m0s; check that the PostgreSQL server is respondinginstead of the baresignal: killed. The callers already handle aGetDb()error: the download returns it to the panel, the Telegram backup and the Discord backup command tell the admin that the backup failed, and the Discord report logs it and is sent without the file.The SQLite path is not changed.
Type of change
Areas affected
How was this tested?
New test
internal/web/service/server_pg_dump_test.go:TestExportPostgresDBGivesUpOnAStalledServerputs a fakepg_dumponPATHthat sleeps for 30 seconds (a server that never answers), setsXUI_DB_DSNand lowerspgDumpTimeoutto 300 ms. It expects the timeout error well before the fake would exit. Skipped on Windows (the fake is a shell script).main(with onlypgDumpTimeoutdeclared so the test compiles) it fails after the full 30 seconds:exportPostgresDB() error = <nil>, want the timeout. With the fix it passes in 0.30 s.Run with Go 1.27.3 and the
internal/web/diststub the CI uses:go build ./...,go vet ./...andgofmt -lare clean.go test -shuffle=on -count=1 ./internal/web/servicepasses.go test -race -shuffle=on -count=1 ./internal/web/servicepasses.Screenshots / recordings
N/A
Breaking changes
None. A
pg_dumpthat runs longer than one hour is now stopped and reported as a failed backup.Checklist
go build ./...and the test suite pass locally.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.