SQLite's default DELETE journal mode combined with an unbounded GORM
connection pool allows multiple goroutines (XrayTrafficJob every 10s,
PeriodicResetJob hourly/daily, WebSocket tickers) to each obtain their
own connection and race for the write lock. When a long-running
transaction holds the lock longer than go-sqlite3's busy_timeout the
competing writer fails with "database is locked" (issue #3739).
Two changes to InitDB:
- Enable WAL journal mode (_journal_mode=WAL, _synchronous=NORMAL):
readers no longer block writers, reducing the write-lock window.
Restores the fix from PR #2645 that was accidentally reverted in
the "revert group management" commit (d18a1a37).
- SetMaxOpenConns(1): serialises all GORM access through a single
connection at the Go pool level so SQLite write-lock contention
cannot occur regardless of transaction duration.
Add database/concurrent_test.go with two test functions:
- TestConcurrentWrites: behavioural proof — reproduces the root cause
(two connections + short busy_timeout → "database is locked"), then
proves SetMaxOpenConns(1) eliminates it by serialising at pool level.
- TestInitDBConcurrencyConfig: verifies InitDB applies both settings,
completing the chain of proof that the production code path is fixed.
Closes#3739
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* chore: implement 2fa auth
from #2786
* chore: format code
* chore: replace two factor token input with qr-code
* chore: requesting confirmation of setting/removing two-factor authentication
otpauth library was taken from cdnjs
* chore: revert changes in `ClipboardManager`
don't need it.
* chore: removing twoFactor prop in settings page
* chore: remove `twoFactorQr` object in `mounted` function
* Revert "json post base path bug fixed (#2647)"
This reverts commit 04cf250a54.
* Revert "Group Management of Subscription Clients"
* Revert "fix getSubGroupClients for enable/disable and edit clients."
* Revert "Enhance database initialization in db.go (#2645)"
This reverts commit 66fe84181b.
* Revert "Add checkpoint handling in CloseDB function (#2646)"
This reverts commit 4dd40f6f19.
* Revert "Improved database model migration and added indexing (#2655)"
This reverts commit b922d986d6.
- Updated GORM configuration to skip default transactions and prepare statements.
- Modified the database connection string to include caching and journal mode settings.
- Executed several PRAGMA statements to optimize SQLite performance and enable foreign key support.
These changes improve database handling and performance in the application.
Co-authored-by: Zakhar Izmaylov <ptdev@kedruss.ru>