{"record":{"id":"e3252ea09d3f8bba","repo":"databendlabs/databend","slug":"failed-to-create-new-grpc-client-function","errorCode":null,"errorMessage":"Failed to create new_grpc_client function: {}","messagePattern":"Failed to create new_grpc_client function: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/meta/control/src/lua_support.rs","lineNumber":404,"sourceCode":"        .map_err(|e| anyhow::anyhow!(\"Failed to create metactl table: {}\", e))?;\n\n    // Register new_grpc_client function\n    let new_grpc_client = lua\n        .create_function(move |_lua, address: String| {\n            let client = MetaGrpcClient::try_create(\n                vec![address],\n                \"root\",\n                \"xxx\",\n                Some(Duration::from_secs(2)),\n                Some(Duration::from_secs(1)),\n                None,\n                DEFAULT_GRPC_MESSAGE_SIZE,\n            )\n            .map_err(|e| mlua::Error::external(format!(\"Failed to create gRPC client: {}\", e)))?;\n\n            Ok(LuaGrpcClient::new(client))\n        })\n        .map_err(|e| anyhow::anyhow!(\"Failed to create new_grpc_client function: {}\", e))?;\n\n    metactl_table\n        .set(\"new_grpc_client\", new_grpc_client)\n        .map_err(|e| anyhow::anyhow!(\"Failed to register new_grpc_client: {}\", e))?;\n\n    // Register new_admin_client function\n    let new_admin_client = lua\n        .create_function(|_lua, address: String| {\n            let client = MetaAdminClient::new(&address);\n            Ok(LuaAdminClient::new(client))\n        })\n        .map_err(|e| anyhow::anyhow!(\"Failed to create new_admin_client function: {}\", e))?;\n\n    metactl_table\n        .set(\"new_admin_client\", new_admin_client)\n        .map_err(|e| anyhow::anyhow!(\"Failed to register new_admin_client: {}\", e))?;\n\n    // Export NULL constant to metactl namespace","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/meta/control/src/lua_support.rs#L386-L422","documentation":"setup_lua_environment registers a `new_grpc_client` Lua function that constructs a MetaGrpcClient. If mlua's create_function fails to wrap the Rust closure, this anyhow error is raised before the function is attached to the metactl table.","triggerScenarios":"Lua environment setup failing at function creation — normally due to mlua state problems, memory pressure, or incompatible mlua/runtime versions in the build.","commonSituations":"Running metactl Lua scripts in builds where the mlua feature set or Lua runtime is broken; heavily constrained environments.","solutions":["Rebuild metactl with a consistent mlua version/feature set","Retry after resolving memory constraints","Upgrade to a release where mlua create_function issues are fixed","Check that no other component corrupted the shared Lua state before setup"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match run_lua_script(&script) {\n    Err(e) if e.to_string().contains(\"Failed to create new_grpc_client\") => {\n        eprintln!(\"Lua function registration failed: {e}; rebuild/retry\");\n    }\n    other => other?,\n}","preventionTips":["Pin a known-good mlua version","Avoid custom Lua sandboxes around the metactl state","Verify Lua scripting works after each binary upgrade","Monitor memory limits in containers running metactl"],"tags":["lua","mlua","grpc","initialization"],"backgroundTag":"module-init-failed","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"}