{"record":{"id":"5b290a37d8151864","repo":"zed-industries/zed","slug":"initialize-query-failed-to-execute-after-retries","errorCode":null,"errorMessage":"Initialize query failed to execute after retries: {}\\n\\nCaused by:\\n{err:#}","messagePattern":"Initialize query failed to execute after retries: (.+?)\\\\n\\\\nCaused by:\\\\n(.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/sqlez/src/thread_safe_connection.rs","lineNumber":231,"sourceCode":"                            && attempt + 1 < CONNECTION_INITIALIZE_RETRIES =>\n                    {\n                        last_error = Some(err);\n                        thread::sleep(CONNECTION_INITIALIZE_RETRY_DELAY);\n                        false\n                    }\n                    Err(err) => {\n                        panic!(\n                            \"Initialize query failed to execute: {}\\n\\nCaused by:\\n{err:#}\",\n                            initialize_query\n                        )\n                    }\n                }\n            });\n\n            if !initialized {\n                let err = last_error\n                    .expect(\"connection initialization retries should record the last error\");\n                panic!(\n                    \"Initialize query failed to execute after retries: {}\\n\\nCaused by:\\n{err:#}\",\n                    initialize_query\n                );\n            }\n        }\n\n        // Disallow writes on the connection. The only writes allowed for thread safe connections\n        // are from the background thread that can serialize them.\n        *connection.write.get_mut() = false;\n\n        connection\n    }\n}\n\nfn is_schema_lock_error(err: &anyhow::Error) -> bool {\n    let message = format!(\"{err:#}\");\n    message.contains(\"database schema is locked\") || message.contains(\"database is locked\")\n}","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/sqlez/src/thread_safe_connection.rs#L213-L249","documentation":"The retry-tolerant sibling of the immediate init failure: ThreadSafeConnection retries schema-lock errors up to CONNECTION_INITIALIZE_RETRIES times, sleeping CONNECTION_INITIALIZE_RETRY_DELAY between attempts. If the schema lock is still held after the final attempt, it panics with 'Initialize query failed to execute after retries' plus the last recorded error (crates/sqlez/src/thread_safe_connection.rs:231).","triggerScenarios":"Another process holding the SQLite schema lock longer than the retry budget — a concurrent Zed instance migrating the same database, or a previous process still alive (hung, or mid-schema-change) while a new one opens the connection.","commonSituations":"Two app instances racing on one db file; a hung process from an earlier session; slow storage stretching migration time past the retry window.","solutions":["Close the other process using the database (check for hung instances with ps) and relaunch.","If it persists, rename the database file so a fresh one is created: mv ~/.config/Zed/db.sqlite ~/.config/Zed/db.sqlite.bak.","On shared/slow storage, ensure only one instance accesses the file at a time.","Check the 'Caused by:' chain to confirm it is a lock error rather than corruption misclassified as retryable."],"exampleFix":"# before: 'Initialize query failed to execute after retries' at startup\n\n# after: stop the other holder, then relaunch\nps aux | grep -i zed   # find the hung instance, kill it\nkill <pid>","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Close other processes using the database before starting a new one.","Check for hung instances (ps) after crashes; kill them before relaunch.","The built-in retry only covers schema locks — corruption needs the file-rename path.","Avoid sharing one db across instances on network storage."],"tags":["sqlite","sqlez","database","lock","retry","startup","panic","zed"],"backgroundTag":"database-initialization-failed","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}