mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6057] [Bug]: mtproto, node sync, and traffic jobs fail with "database is locked" #4189
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#4189
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 @qlampa on GitHub (Jul 20, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6057
Describe the bug
Getting error as of title when x-ui running for sometime. After reboot mtproto seems to start working again, not really sure what causes this. Used database is sqlite. By the way there's also other warning saying same for other services.
How to reproduce the problem
Expected behavior
No response
Actual behavior
No response
Relevant logs
Screenshots
No response
3x-ui version
3.5.0
Xray-core version
26.7.11
How did you install 3x-ui?
install.sh script
Operating system
Debian 12
Which parts of the panel are affected?
No response
Browser (only if it is a UI bug)
No response
Is the panel behind a reverse proxy or CDN?
None
Before submitting
@github-actions[bot] commented on GitHub (Jul 20, 2026):
Title: SQLite lock contention across cron jobs, worsened by the switch to rollback-journal (
DELETE) modeSeverity: Medium
Category: Reliability
Why this matters:
Every warning line in your log maps to a different cron job independently hitting
SQLITE_BUSY("database is locked") on the shared SQLite handle — it's not one misbehaving job:mtproto job: get desired instances failed→internal/web/job/mtproto_job.go:28node heartbeat: load nodes failed→internal/web/job/node_heartbeat_job.go:39node traffic sync: load nodes failed→internal/web/job/node_traffic_sync_job.go:94add inbound traffic failed→internal/web/job/xray_traffic_job.go:49client ip job err→internal/web/job/check_client_ip_job.go:460Each job simply
returns on error and waits for its next tick, so nothing is corrupted, but traffic accounting, node up/down detection, mtg sidecar reconciliation, and IP-limit enforcement all silently skip that cycle. This is also a long-running, recurring class of report (#3739 and older ones going back to #179/#522/#728/#1777), so it's worth treating as a genuine reliability gap rather than a one-off.Two things compound to cause it, both confirmed in the current source (same as what ships in v3.5.0, the version you reported):
internal/web/web.go:289-293schedulescadenceXrayTraffic,cadenceNodeHeartbeat, andcadenceNodeTrafficall at@every 5s, andcadenceMtproto/cadenceClientIPScanboth at@every 10s— all registered back-to-back at startup with no stagger, so they tend to land on the same tick. The comment directly above that block already flags this: "add per-tick jitter to de-synchronize fleet load" is listed as a not-yet-implemented follow-up (web.go:280-285).e079490144("chore(db): use DELETE journal mode so sqlite stays a single file", 2026-06-19) changed the DSN from_journal_mode=WAL&..._synchronous=NORMALto_journal_mode=DELETE&..._synchronous=FULL(internal/database/db.go:1790, pragmas at 1800-1807), intentionally trading concurrency for a singlex-ui.dbfile at rest with no-wal/-shmsidecars. InDELETEmode a writer's commit needs an exclusive lock that blocks concurrent readers (and vice versa); in WAL mode readers and writers don't block each other.busy_timeoutis correctly set to 10s in both the DSN and a PRAGMA (db.go:1790,1802) and does apply per pooled connection, so this isn't a missing-timeout bug — contention is genuinely exceeding 10s on installs like yours. For example,InboundService.AddTraffic(internal/web/service/inbound_traffic.go:24-36) opens one write transaction covering inbound traffic, client traffic, auto-renew and auto-disable every 5s (xray_traffic_job.go:47), which can hold the write lock long enough to block the plainSELECTsNodeService.GetAll()(internal/web/service/node.go:103-106) runs on the same 5s cadence.Recommendation:
web.go:280-285so the 5s/10s jobs stop landing on the same instant.DELETE+FULLtrade-off frome079490144. If the single-file-at-rest property mainly matters for backup/export, keeping WAL for normal operation and checkpointing (database.Checkpoint()is already wired into the export/import paths atinternal/web/service/server.go:1307and:1425) around that specific operation would preserve both properties without paying the concurrency cost on every tick.internal/web/service/traffic_writer.goalready serializes the traffic-write path through one goroutine (submitTrafficWrite), so writes have partial protection; the node-heartbeat/traffic-sync/mtproto reads in this report aren't part of that queue and can still be blocked by whatever write is in flight underDELETEmode.As a config-only mitigation to test in the meantime: set
XUI_DB_SYNCHRONOUS=NORMALin/etc/default/x-uiandsystemctl restart x-ui(read atinternal/database/db.go:1854-1865; default isFULL, which fsyncs on every commit). This shortens how long each write holds the lock, which should reduce — not eliminate — how often the 10sbusy_timeoutis exceeded. It's an existing, supported env var, but it does slightly weaken crash durability versusFULL: SQLite may lose the most recent commit (not corrupt the file) if the OS crashes or power is lost immediately after a write.Example:
Confidence: High that the mechanism above is a real, currently-present contributor to these warnings — grounded directly in the current source and the commit that introduced the
DELETE-mode switch. Medium on whether it's the sole cause on this specific server, since lock hold time also scales with disk I/O speed and the number of inbounds/clients/nodes, which aren't in the report.If you can share roughly how many inbounds/clients/nodes this panel manages and whether the disk is local SSD or network-backed storage, that would help gauge how much headroom the jitter/WAL changes would need to provide.
@MHSanaei for a decision on the journal-mode trade-off and/or cadence jitter.
This reply was generated automatically; a maintainer may follow up.
@MHSanaei commented on GitHub (Jul 23, 2026):
Fixed in #6083. SQLite now defaults to WAL, so background jobs no longer serialize into 'database is locked'. Checkpoint() truncates the WAL so backups stay single-file; XUI_DB_JOURNAL_MODE=DELETE restores the old mode.