daboross/fern

double free or corruption (out)

Closed this issue · 1 comments

Hello.

Fern version: 0.6.2
Rust version: rustc 1.75.0 (82e1608df 2023-12-21)

I've been troubleshooting my application for a while now, since i kept getting the error: double free or corruption (out) from rust, whenever i ran the application. After some digging it turns out, that fern (Quite possibly) is the culprit.

I might be using it in a "wrong way" that is causing the issue, but i would still like to ask here to get some clarification..

The thing is that i have a Library that is a dependency for multiple crates in the workspace i'm in. Since all of the crates need some sort of streamlined logging, i have created a function that creates the fern logger in the library like so:

pub fn setup_logger() {
    // Setup logger
    fern::Dispatch::new()
        .format(|out, message, record| {
            out.finish(format_args!(
                "[{}][{}][{}] {}",
                chrono::Local::now().format("%Y-%m-%d %H:%M:%S"),
                record.target(),
                record.level(),
                message
            ));
        })
        // Filter out debug if in release-mode
        .level(if cfg!(debug_assertions) {
            log::LevelFilter::Debug
        } else {
            log::LevelFilter::Info
        })
        // Ouput to both stdout, log-server and log-file
        .chain(std::io::stdout())
        .apply()
        .expect("Couldn't setup logger");
}

I use this function like so in other crates:

fn main {
    mylibrary::setup_logger();
    
    // Do stuff
}

Whenever i launch this command everything works fine - However, in combination with Rocket, Diesel and rocket_sync_db_pools something seems to break - Removing the setup_logger function will actually make the program run properly.

Am i doing something wrong here? Or is it just not possible because of so many threaded things? (I'm not really an expert on the nitty-gritty low-level stuff, so i don't really get how this happens).

It also needs to be said that this worked fine, before putting Diesel and DB-pools on top - But diesel and DB-pools works fine without fern...

EDIT: It seems Fern isn't exactly the sole culprit - There are multiple things at play - Being discussed in this issue

The issue originated in openssl and diesel.