{"record":{"id":"9b88bf82af489f68","repo":"dagger/dagger","slug":"close-db-before-import-wipe","errorCode":null,"errorMessage":"close db before import-wipe","messagePattern":"close db before import-wipe","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dagql/cache.go","lineNumber":473,"sourceCode":"\t\t\treturn nil, errors.Join(fmt.Errorf(\"close db before wipe\"), closeErr)\n\t\t}\n\t\tif err := wipeSQLiteFiles(dbPath); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"wipe unclean persistence db: %w\", err)\n\t\t}\n\n\t\tdb, persistDB, err = prepareCacheDBs(ctx, dbPath)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tc.sqlDB = db\n\t\tc.pdb = persistDB\n\t}\n\tif err := c.importPersistedState(ctx); err != nil {\n\t\tc.persistenceResetReason = CachePersistenceResetImportFailure\n\t\tc.tracePersistStoreWipedImportFailure(ctx, err)\n\t\tslog.Warn(\"dagql persistence import failed; wiping and cold-starting\", \"err\", err)\n\t\tif closeErr := closeCacheDBs(db, c.pdb); closeErr != nil {\n\t\t\treturn nil, errors.Join(fmt.Errorf(\"close db before import-wipe\"), closeErr)\n\t\t}\n\t\tif err := wipeSQLiteFiles(dbPath); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"wipe persistence db after import failure: %w\", err)\n\t\t}\n\t\tdb, persistDB, err = prepareCacheDBs(ctx, dbPath)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tc.sqlDB = db\n\t\tc.pdb = persistDB\n\t}\n\n\tif err := c.pdb.UpsertMeta(ctx, persistdb.MetaKeySchemaVersion, cachePersistenceSchemaVersion); err != nil {\n\t\tif closeErr := closeCacheDBs(db, c.pdb); closeErr != nil {\n\t\t\treturn nil, errors.Join(fmt.Errorf(\"set persistence schema version: %w\", err), closeErr)\n\t\t}\n\t\treturn nil, fmt.Errorf(\"set persistence schema version: %w\", err)\n\t}","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/dagql/cache.go#L455-L491","documentation":"When importing persisted state back into the freshly opened cache fails, NewCache attempts a wipe-and-cold-start recovery. Before wiping it must close both DBs; if closeCacheDBs fails, this \"close db before import-wipe\" error is returned (joined with the close error), aborting startup instead of performing the recovery wipe.","triggerScenarios":"c.importPersistedState(ctx) returns an error (corrupt/incompatible persisted data, parse failure, context cancelled), then closeCacheDBs(db, c.pdb) also returns an error during the recovery path.","commonSituations":"Persistence snapshot written by an older/newer Dagger version with incompatible format; truncated cache file after crash; recovery running on a disk that is full or has a locked DB (another instance attached); context deadline exceeded during long import.","solutions":["Stop any other dagger/engine process sharing the cache path, then restart so the close+wipe can succeed.","Check free disk space and filesystem health before restarting.","Delete the persistence files manually while the engine is stopped and let the next start cold-initialize.","Ensure the same Dagger version is used for the cache dir (avoid version mixing on shared volumes)."],"exampleFix":"// before: import fails, close also fails (second instance holds lock)\n$ dagger run ...  # aborts\n// after\n$ kill <other-engine-pid>; rm -f /var/lib/dagger/cache.db*; restart dagger","handlingStrategy":"try-catch","validationCode":"// only one instance, writable dir, sane timeout before an import-heavy init\nfunc preflight(dbPath string) error {\n\tif err := unix.Access(dbPath, unix.W_OK); err != nil { return err }\n\treturn os.MkdirAll(filepath.Dir(dbPath+\".lock\"), 0o755) // + lockfile discipline\n}","typeGuard":null,"tryCatchPattern":"c, err := dagql.NewCache(ctx, dbPath, sm, gc)\nif err != nil && strings.Contains(err.Error(), \"close db before import-wipe\") {\n\t// another holder blocked the recovery close: clear and retry once\n\tos.Remove(dbPath); os.Remove(dbPath+\"-wal\"); os.Remove(dbPath+\"-shm\")\n\tc, err = dagql.NewCache(ctx, dbPath, sm, gc)\n}\nif err != nil { return err }","preventionTips":["Never run two engines against one cache dir","Give startup a generous context timeout for large persisted state","Keep the cache on reliable local storage","Upgrade the whole fleet to the same Dagger version before sharing volumes"],"tags":["sqlite","persistence","import","close-failed"],"backgroundTag":"sqlite-close-failed","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}