{"record":{"id":"bb6d1e98ad4feb3a","repo":"shadowsocks/shadowsocks-rust","slug":"syslog-is-already-initialized","errorCode":null,"errorMessage":"syslog is already initialized","messagePattern":"syslog is already initialized","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/logging/tracing.rs","lineNumber":217,"sourceCode":"            9 => Facility::Cron,\n            10 => Facility::AuthPriv,\n            16 => Facility::Local0,\n            17 => Facility::Local1,\n            18 => Facility::Local2,\n            19 => Facility::Local3,\n            20 => Facility::Local4,\n            21 => Facility::Local5,\n            22 => Facility::Local6,\n            23 => Facility::Local7,\n            _ => panic!(\"unsupported syslog facility: {}\", f),\n        },\n    };\n    let options = Options::default();\n    let identity = CString::new(identity).expect(\"syslog identity contains null-byte ('\\\\0')\");\n\n    match Syslog::new(identity, options, facility) {\n        Some(l) => l,\n        None => panic!(\"syslog is already initialized\"),\n    }\n}\n","sourceCodeStart":199,"sourceCodeEnd":220,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/src/logging/tracing.rs#L199-L220","documentation":"The syslog crate's Syslog::new returns None when a syslog connection was already opened in the process (only one syslog target per process). make_syslog_writer panics in that case because it cannot create a second writer. This happens when syslog logging is initialized more than once, e.g. building the logger layer twice.","triggerScenarios":"Calling make_syslog_writer/make_layer a second time after a prior Syslog::new succeeded — e.g. re-running logging initialization, or initializing both a local logger and an additional syslog layer that each call Syslog::new.","commonSituations":"Calling initialize_logging twice during startup; reconfiguring logging at runtime by rebuilding layers; tests that initialize syslog logging repeatedly in one process.","solutions":["Initialize logging/syslog exactly once per process; reuse the existing writer","Guard logger setup with std::sync::Once or a OnceLock","If reconfiguring, tear down and don't call Syslog::new again — the connection persists"],"exampleFix":"// before\nfn init_logs() {\n    make_layer(); // called twice -> panic\n}\n// after\nstatic INIT: Once = Once::new();\nfn init_logs() {\n    INIT.call_once(make_layer);\n}","handlingStrategy":"validation","validationCode":"static SYSLOG_INIT: std::sync::Once = std::sync::Once::new();\nSYSLOG_INIT.call_once(|| { make_layer(); }); // prevent second Syslog::new","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Initialize logging once per process using Once/OnceLock","Do not rebuild logging layers at runtime if syslog is among them","In tests, use one shared syslog init or skip syslog targets","Document that only one syslog writer may exist per process"],"tags":["panic","logging","syslog","double-initialization"],"backgroundTag":"invalid-state-transition","analyzedSha":"8eb0f0a65b1d976ab6bed5787327ef86529b0435","analyzedAt":"2026-09-09T12:20:43.168Z","contentChangedAt":"2026-09-09T12:20:43.168Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}