{"record":{"id":"b62a541466376455","repo":"linera-io/linera-protocol","slug":"failed-to-get-local-address","errorCode":null,"errorMessage":"Failed to get local address","messagePattern":"Failed to get local address","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"linera-metrics/src/monitoring_server.rs","lineNumber":105,"sourceCode":"/// `register_metrics` is the caller's `init_metrics`. It is a parameter rather than a direct\n/// call because this crate sits below `linera-views` and friends in the dependency graph and\n/// cannot reach their metrics; taking it here makes forgetting to register a compile error\n/// instead of a metric that silently only appears once its code path first runs.\npub fn start_metrics(\n    address: impl ToSocketAddrs + Debug + Send + 'static,\n    shutdown_signal: CancellationToken,\n    memory_profiling: MemoryProfiling,\n    register_metrics: impl FnOnce(),\n) {\n    crate::runtime_metrics::register();\n    register_metrics();\n    let app = metrics_router(memory_profiling);\n\n    tokio::spawn(async move {\n        let listener = tokio::net::TcpListener::bind(address)\n            .await\n            .expect(\"Failed to bind to address\");\n        let address = listener.local_addr().expect(\"Failed to get local address\");\n\n        info!(\"Starting to serve metrics on {:?}\", address);\n        if let Err(e) = axum::serve(listener, app)\n            .with_graceful_shutdown(shutdown_signal.cancelled_owned())\n            .await\n        {\n            panic!(\"Error serving metrics: {e}\");\n        }\n    });\n}\n\nfn metrics_router(memory_profiling: MemoryProfiling) -> Router {\n    #[cfg(feature = \"jemalloc\")]\n    if memory_profiling == MemoryProfiling::Enabled {\n        match MemoryProfiler::check_prof_ctl() {\n            Ok(()) => {\n                info!(\"Memory profiling enabled, registering /debug/pprof and /debug/flamegraph endpoints\");\n                return Router::new()","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-metrics/src/monitoring_server.rs#L87-L123","documentation":"Immediately after a successful TcpListener::bind, start_metrics calls listener.local_addr() and expects success (linera-metrics/src/monitoring_server.rs:105). local_addr only fails if the socket is already closed, which cannot happen between a successful bind and this call. This expect is defensive boilerplate and is effectively unreachable in practice.","triggerScenarios":"No realistic trigger: it would require the listener to be closed between bind() and local_addr() within the same async block, which standard tokio usage cannot produce.","commonSituations":"None - if this message appears, it points to memory corruption or an exotic runtime fault, not to configuration or usage.","solutions":["Treat a hit of this panic as a bug report: capture the backtrace and file it against linera-metrics.","Restart the affected service; this is not caused by ports, config, or load."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["No actionable prevention; this expect guards an impossible state after a successful bind.","If observed, collect a backtrace and report it as a linera-metrics bug."],"tags":["linera-metrics","unreachable","defensive-panic","rust"],"backgroundTag":null,"analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}