{"record":{"id":"8df6987fa2a4c0d5","repo":"t8y2/dbx","slug":"failed-to-install-rustls-crypto-provider","errorCode":null,"errorMessage":"Failed to install rustls crypto provider","messagePattern":"Failed to install rustls crypto provider","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbx-web/src/main.rs","lineNumber":293,"sourceCode":"        .route(\"/mq/raw\", post(routes::mq::raw_request))\n        .route(\"/mq/send-message\", post(routes::mq::send_message))\n}\n\n#[cfg(not(feature = \"mq-admin\"))]\nfn add_mq_routes(router: Router<Arc<WebState>>) -> Router<Arc<WebState>> {\n    router\n}\n\n#[tokio::main]\nasync fn main() {\n    tracing_subscriber::fmt()\n        .with_env_filter(\n            tracing_subscriber::EnvFilter::try_from_default_env()\n                .unwrap_or_else(|_| \"dbx_web=info,tower_http=info\".parse().unwrap()),\n        )\n        .init();\n\n    rustls::crypto::aws_lc_rs::default_provider().install_default().expect(\"Failed to install rustls crypto provider\");\n\n    // Data directory\n    let data_dir = std::env::var(\"DBX_DATA_DIR\").map(std::path::PathBuf::from).unwrap_or_else(|_| {\n        let home = std::env::var(\"HOME\").unwrap_or_else(|_| \".\".to_string());\n        std::path::PathBuf::from(home).join(\".dbx-web\")\n    });\n    std::fs::create_dir_all(&data_dir).expect(\"Failed to create data directory\");\n\n    let app_state = {\n        let db_path = data_dir.join(\"dbx.db\");\n        let storage = Storage::open(&db_path).await.expect(\"Failed to open storage\");\n        storage.migrate_from_json(&data_dir).await.expect(\"Failed to migrate JSON data\");\n\n        // Initialize core dialect registry and load external plugin dialects\n        register_core_dialects();\n        let registry = DialectRegistry::global();\n        let plugin_dirs = vec![data_dir.join(\"plugins\").join(\"dialects\")];\n        let load_result = DialectPluginLoader::scan_and_load(registry, &plugin_dirs);","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/crates/dbx-web/src/main.rs#L275-L311","documentation":"At startup dbx-web installs a rustls crypto provider (aws_lc_rs) as the process-wide default before building TLS clients. install_default() returns Err if a default provider is already installed, and the code panics via expect().","triggerScenarios":"main() runs rustls::crypto::aws_lc_rs::default_provider().install_default().expect(...) when another rustls default provider was already installed earlier in the same process — e.g., an embedding host, a test harness, or another library calling install_default first.","commonSituations":"Running dbx-web embedded in another binary that configures rustls; tests that init TLS twice; a dependency (e.g., reqwest with rustls feature) installing a provider during an init hook; duplicated main paths in the same binary.","solutions":["Guard the install: only install if rustls::crypto::CryptoProvider::get_default().is_none().","If embedding, install the provider once at process start before calling dbx-web's main/init.","Ensure only one crypto provider feature is enabled (aws_lc_rs vs ring) to avoid conflicting initialization order."],"exampleFix":"// before\nrustls::crypto::aws_lc_rs::default_provider().install_default().expect(\"Failed to install rustls crypto provider\");\n// after\nif rustls::crypto::CryptoProvider::get_default().is_none() {\n    rustls::crypto::aws_lc_rs::default_provider()\n        .install_default()\n        .expect(\"Failed to install rustls crypto provider\");\n}","handlingStrategy":"try-catch","validationCode":"if rustls::crypto::CryptoProvider::get_default().is_some() {\n    // provider already installed; skip install_default\n}","typeGuard":"fn crypto_provider_installed() -> bool {\n    rustls::crypto::CryptoProvider::get_default().is_some()\n}","tryCatchPattern":"if crypto_provider_installed() {\n    tracing::debug!(\"rustls default provider already installed; skipping\");\n} else {\n    rustls::crypto::aws_lc_rs::default_provider()\n        .install_default()\n        .expect(\"Failed to install rustls crypto provider\");\n}","preventionTips":["Install a rustls crypto provider exactly once, at the earliest point of the process.","Enable only one provider feature (aws_lc_rs or ring) across dependencies.","Check CryptoProvider::get_default() before calling install_default in embedded contexts."],"tags":["rust","tls","rustls","startup"],"backgroundTag":"crypto-provider-already-installed","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}