{"record":{"id":"891d3c5d72131f31","repo":"henrygd/beszel","slug":"failed-to-delete-old-container-records-v","errorCode":null,"errorMessage":"failed to delete old container records: %v","messagePattern":"failed to delete old container records: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/records/records_deletion.go","lineNumber":124,"sourceCode":"\n\t// Delete systemd service records where updated < twentyMinutesAgo\n\t_, err := app.DB().NewQuery(\"DELETE FROM systemd_services WHERE updated < {:updated}\").Bind(dbx.Params{\"updated\": twentyMinutesAgo.UnixMilli()}).Execute()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to delete old systemd service records: %v\", err)\n\t}\n\n\treturn nil\n}\n\n// Deletes container records that haven't been updated in the last 10 minutes\nfunc deleteOldContainerRecords(app core.App) error {\n\tnow := time.Now().UTC()\n\ttenMinutesAgo := now.Add(-10 * time.Minute)\n\n\t// Delete container records where updated < tenMinutesAgo\n\t_, err := app.DB().NewQuery(\"DELETE FROM containers WHERE updated < {:updated}\").Bind(dbx.Params{\"updated\": tenMinutesAgo.UnixMilli()}).Execute()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to delete old container records: %v\", err)\n\t}\n\n\treturn nil\n}\n\n// Deletes old quiet hours records where end date has passed\nfunc deleteOldQuietHours(app core.App) error {\n\tnow := time.Now().UTC()\n\t_, err := app.DB().NewQuery(\"DELETE FROM quiet_hours WHERE type = 'one-time' AND end < {:now}\").Bind(dbx.Params{\"now\": now}).Execute()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":106,"sourceCodeEnd":140,"githubUrl":"https://github.com/henrygd/beszel/blob/b38fb7dafa60812cc22e6a84ce313e94f1ce0a32/internal/records/records_deletion.go#L106-L140","documentation":"deleteOldContainerRecords runs a DELETE on the containers collection for rows not updated in the last 10 minutes. Query execution failure is wrapped in this error, pointing at container-record retention cleanup.","triggerScenarios":"The DELETE FROM containers query fails due to database lock, disk full, or the containers collection missing from the schema.","commonSituations":"SQLite lock contention with concurrent writes; schema drift after upgrades; full disk on the hub preventing writes.","solutions":["Inspect the wrapped error for the underlying SQLite cause","Verify the containers collection exists and is not locked by another process","Free disk space / resolve DB lock contention, then let the cleanup job retry"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if !collectionExists(app, \"containers\") {\n    return errors.New(\"containers collection missing\")\n}","typeGuard":null,"tryCatchPattern":"if err := deleteOldContainerRecords(app); err != nil {\n    log.Error().Err(err).Msg(\"container retention cleanup failed\")\n    // inspect wrapped SQLite error, resolve lock/disk issue, retry\n}","preventionTips":["Keep the containers collection name stable across migrations","Avoid concurrent exclusive DB access during cleanup","Monitor disk space; alert on repeated cleanup failures"],"tags":["database","sqlite","retention","containers"],"backgroundTag":"database-delete-failed","analyzedSha":"b38fb7dafa60812cc22e6a84ce313e94f1ce0a32","analyzedAt":"2026-08-31T15:10:10.149Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}