fix: harden deepseek official remote43 import closure

This commit is contained in:
phamnazage-jpg
2026-05-27 07:56:24 +08:00
parent bcfc08568c
commit c1172d7714
12 changed files with 172 additions and 29 deletions

View File

@@ -44,6 +44,11 @@ func Open(ctx context.Context, dsn string) (*DB, error) {
if err != nil {
return nil, fmt.Errorf("open sqlite database: %w", err)
}
// SQLite only tolerates a single writer at a time. Pin the pool to one
// connection so HTTP flows that chain several writes (for example host
// probe refresh + import persistence) do not self-deadlock into SQLITE_BUSY.
sqlDB.SetMaxOpenConns(1)
sqlDB.SetMaxIdleConns(1)
if err := sqlDB.PingContext(ctx); err != nil {
_ = sqlDB.Close()

View File

@@ -15,6 +15,24 @@ func TestOpenClose(t *testing.T) {
}
}
func TestOpenPinsSingleSQLiteConnection(t *testing.T) {
dbPath := filepath.Join(t.TempDir(), "single-conn.db")
store, err := Open(context.Background(), "file:"+filepath.ToSlash(dbPath)+"?_busy_timeout=5000")
if err != nil {
t.Fatalf("Open() error = %v", err)
}
defer func() {
if err := store.Close(); err != nil {
t.Fatalf("Close() error = %v", err)
}
}()
stats := store.SQLDB().Stats()
if stats.MaxOpenConnections != 1 {
t.Fatalf("MaxOpenConnections = %d, want 1", stats.MaxOpenConnections)
}
}
func TestOpenInvalidDSN(t *testing.T) {
_, err := Open(context.Background(), "file:/nonexistent/dir/test.db?_pragma=foreign_keys(0)")
if err == nil {