shadowsocks/shadowsocks-rust · error

syslog is already initialized

Error message

syslog is already initialized

What it means

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.

Source

Thrown at src/logging/tracing.rs:217

            9 => Facility::Cron,
            10 => Facility::AuthPriv,
            16 => Facility::Local0,
            17 => Facility::Local1,
            18 => Facility::Local2,
            19 => Facility::Local3,
            20 => Facility::Local4,
            21 => Facility::Local5,
            22 => Facility::Local6,
            23 => Facility::Local7,
            _ => panic!("unsupported syslog facility: {}", f),
        },
    };
    let options = Options::default();
    let identity = CString::new(identity).expect("syslog identity contains null-byte ('\\0')");

    match Syslog::new(identity, options, facility) {
        Some(l) => l,
        None => panic!("syslog is already initialized"),
    }
}

View on GitHub (pinned to 8eb0f0a65b)

Solutions

  1. Initialize logging/syslog exactly once per process; reuse the existing writer
  2. Guard logger setup with std::sync::Once or a OnceLock
  3. If reconfiguring, tear down and don't call Syslog::new again — the connection persists

Example fix

// before
fn init_logs() {
    make_layer(); // called twice -> panic
}
// after
static INIT: Once = Once::new();
fn init_logs() {
    INIT.call_once(make_layer);
}
Defensive patterns

Strategy: validation

Validate before calling

static SYSLOG_INIT: std::sync::Once = std::sync::Once::new();
SYSLOG_INIT.call_once(|| { make_layer(); }); // prevent second Syslog::new

Prevention

When it happens

Trigger: 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.

Common situations: Calling initialize_logging twice during startup; reconfiguring logging at runtime by rebuilding layers; tests that initialize syslog logging repeatedly in one process.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of shadowsocks/shadowsocks-rust@8eb0f0a65b (2026-09-09). Data as JSON: /api/errors/bb6d1e98ad4feb3a. Report an issue: GitHub.