From 814fbe0dae86184f24e150228fc346e0e76dd5d1 Mon Sep 17 00:00:00 2001 From: NanamiAdmin Date: Wed, 5 Aug 2026 13:31:25 +0800 Subject: [PATCH] fix(database): fix sqlite init error in smb workspace fix(postLog/database): change journal mode from WAL to DELETE --- .gitignore | 10 +++++++++- config/config.go | 2 +- database/user.go | 17 +++++++++++++++++ db/log.db | 0 db/user.db | Bin 16384 -> 0 bytes logs.db/log.db | 0 logs.db/user.db | Bin 16384 -> 0 bytes postLog/database.go | 35 ++++++++++++++++++++++++++++++++--- 8 files changed, 59 insertions(+), 5 deletions(-) delete mode 100644 db/log.db delete mode 100644 db/user.db delete mode 100644 logs.db/log.db delete mode 100644 logs.db/user.db diff --git a/.gitignore b/.gitignore index 0186ae4..43d1884 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,11 @@ /.claude agent.md -config.json \ No newline at end of file +config.json + +# SQLite database files. They live on a network share (Y:), and git/cloud +# sync touching them while a WAL database is open corrupts the WAL index and +# crashes the process (EXCEPTION_IN_PAGE_ERROR). Never track these. +db/*.db +db/*.db-wal +db/*.db-shm +db/*.db-journal \ No newline at end of file diff --git a/config/config.go b/config/config.go index 2966aab..c362065 100644 --- a/config/config.go +++ b/config/config.go @@ -78,7 +78,7 @@ func LoadConfig(configPath string) (*Config, error) { cfg.DataPath = "./data" } if cfg.DBPath == "" { - cfg.DBPath = "./logs.db" + cfg.DBPath = "./db" } // Apply default message templates if not specified. diff --git a/database/user.go b/database/user.go index 663da77..2013609 100644 --- a/database/user.go +++ b/database/user.go @@ -38,6 +38,23 @@ func InitUserDB(dbPath string) error { return fmt.Errorf("failed to ping user database: %w", err) } + // Use the rollback journal (DELETE) instead of WAL. + // + // WAL memory-maps a -shm index file. modernc.org/sqlite (a C-to-Go + // transpile) is built without SEH on Windows, so an I/O page fault on that + // mapping (common when the database lives on an SMB/network share) + // terminates the process with EXCEPTION_IN_PAGE_ERROR instead of being + // caught and retried. With SetMaxOpenConns(1) above, WAL provides no + // concurrency benefit either, so the rollback journal is strictly better. + if _, err := UserDB.Exec("PRAGMA journal_mode=DELETE"); err != nil { + return fmt.Errorf("failed to set journal mode: %w", err) + } + + // Wait up to 5 seconds for a busy database instead of immediately failing with SQLITE_BUSY. + if _, err := UserDB.Exec("PRAGMA busy_timeout=5000"); err != nil { + return fmt.Errorf("failed to set busy timeout: %w", err) + } + if err := initUserTable(); err != nil { return fmt.Errorf("failed to initialize user table: %w", err) } diff --git a/db/log.db b/db/log.db deleted file mode 100644 index e69de29..0000000 diff --git a/db/user.db b/db/user.db deleted file mode 100644 index c341f40bbced9de9863022bc4268d1e5a8108924..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI%&q~8E90%}p8`Dkp=hka(+t?7qvtZRI#je|GD(+OOjZ)}3*LLbvdWK zdZ}0}MSQnDteiT`;EZzP#A0+Uwj291F_4+P*K2J@*LCe}FMsAT6-k;mr9yr_MZ5J{ zEexn>b9TWTI(E#V;Y{fzn^ME&Bh!{SLuT`Vj8hqE7s}ZUr}juz*RrT00Izz00bZa0SG_<0uX?}whGkM!EpcI z*4K-3K>z{}fB*y_009U<00Izz00eRY{Qt*?009U<00Izz00bZa0SG_<0ub1KfnQH; Bb$WK zdZ}0}MSQnDteiT`;EZzP#A0+Uwj291F_4+P*K2J@*LCe}FMsAT6-k;mr9yr_MZ5J{ zEexn>b9TWTI(E#V;Y{fzn^ME&Bh!{SLuT`Vj8hqE7s}ZUr}juz*RrT00Izz00bZa0SG_<0uX?}whGkM!EpcI z*4K-3K>z{}fB*y_009U<00Izz00eRY{Qt*?009U<00Izz00bZa0SG_<0ub1KfnQH; Bb$