{"record":{"id":"659cdcaa4a6d89a0","repo":"databendlabs/databend","slug":"internal-error-entered-unreachable-code-659cdc","errorCode":null,"errorMessage":"internal error: entered unreachable code","messagePattern":"internal error: entered unreachable code","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/service/src/catalogs/default/session_catalog.rs","lineNumber":596,"sourceCode":"            TxnState::AutoCommit => {\n                let update_temp_tables = std::mem::take(&mut req.update_temp_tables);\n                let reply = if req.is_empty() {\n                    Ok(Default::default())\n                } else {\n                    self.inner\n                        .retryable_update_multi_table_meta(tenant, req)\n                        .await?\n                };\n                self.temp_tbl_mgr\n                    .lock()\n                    .update_multi_table_meta(update_temp_tables);\n                Ok(reply)\n            }\n            TxnState::Active => {\n                self.txn_mgr.lock().update_multi_table_meta(tenant, req)?;\n                Ok(Ok(Default::default()))\n            }\n            TxnState::Fail => unreachable!(),\n        }\n    }\n\n    async fn set_table_row_access_policy(\n        &self,\n        req: SetTableRowAccessPolicyReq,\n    ) -> Result<SetTableRowAccessPolicyReply> {\n        if is_temp_table_id(req.table_id) {\n            return Err(ErrorCode::StorageUnsupported(format!(\n                \"SetTableRowAccessPolicy: table id {} is a temporary table id\",\n                req.table_id\n            )));\n        }\n        self.inner.set_table_row_access_policy(req).await\n    }\n\n    async fn set_table_column_mask_policy(\n        &self,","sourceCodeStart":578,"sourceCodeEnd":614,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/service/src/catalogs/default/session_catalog.rs#L578-L614","documentation":"`unreachable!()` in `SessionCatalog::retryable_update_multi_table_meta` (session_catalog.rs): after replaying/committing a multi-table transaction, the code matches the transaction state and asserts `TxnState::Fail` is impossible on this path — a failed txn is expected to be retried or surfaced as an error earlier. Hitting it means the transaction manager returned a Fail state where only Committed/Active were expected, i.e. transaction state-machine corruption or a missing retry branch.","triggerScenarios":"Calling DDL/metadata operations (`update_multi_table_meta`) inside an explicit transaction whose state is `TxnState::Fail` — e.g. after a prior statement in the transaction failed but the session retried the metadata update without aborting/rolling back the failed transaction.","commonSituations":"Multi-statement transactions where one statement errored and a subsequent metadata update is retried; failed commits not cleaned up before retryable updates; meta-service (FDB-like) errors leaving txn state as Fail on the session catalog.","solutions":["Roll back / abort the failed transaction before issuing further metadata updates (ROLLBACK, or start a new transaction).","Check prior errors in the session — the Fail state usually stems from an earlier failed statement that must be handled, not retried.","Upgrade Databend; ensure `retryable_update_multi_table_meta` converts `TxnState::Fail` into a proper error instead of panicking.","Inspect transaction-manager logs and file an issue with the DDL sequence if the state appears inconsistent."],"exampleFix":"// before\nTxnState::Fail => unreachable!(),\n// after\nTxnState::Fail => Err(ErrorCode::TxnFailed(\n    \"cannot retry update_multi_table_meta on failed transaction; abort and retry the transaction\",\n)),","handlingStrategy":"try-catch","validationCode":"// application-side: only issue metadata DDL while the txn state is Active\nif txn_state() != TxnState::Active { abort_and_restart_txn(); }","typeGuard":null,"tryCatchPattern":"// treat TxnState::Fail surfaced as unreachable panic as a txn-abort requirement\nmatch exec(ddl) {\n    Err(e) if e.to_string().contains(\"entered unreachable code\") => { rollback(); retry_txn(); }\n    other => other,\n}","preventionTips":["Always ROLLBACK after any failed statement inside an explicit transaction before retrying DDL.","Never reuse a session/transaction after a commit failure without aborting.","Upgrade to builds where Fail converts to a typed transaction error.","Monitor txn-manager logs for Fail states preceding metadata updates."],"tags":["rust","panic","transaction","metadata","catalog"],"backgroundTag":"invalid-state-transition","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}