Skip to content

Signal handler consumes 100% CPU if backend thread stopped and segfault #906

@olivermadge

Description

@olivermadge

Describe the bug
If a SIGSEGV signal handler is installed, and the backend thread is stopped, then a segfault causes the program to hang consuming 100% CPU.

In the contrived example below I deliberately provoke a segfault, but more realistically this would happen during destruction of a C++ class when a class goes out of scope, for example at program exit.

To Reproduce

#include "quill/Backend.h"
#include <quill/Frontend.h>
#include "quill/LogMacros.h"
#include "quill/Logger.h"
#include "quill/Utility.h"
#include "quill/sinks/ConsoleSink.h"
#include "quill/sinks/FileSink.h"

int main() {
    //quill::Backend::start(quill::BackendOptions {}); <-- if the signal handler isn't registered there is no problem
    quill::Backend::start<quill::FrontendOptions>(quill::BackendOptions {}, quill::SignalHandlerOptions {});

    auto console_sink = quill::Frontend::create_or_get_sink<quill::ConsoleSink>("sink_id_1");
    quill::Frontend::create_or_get_logger("logger", {std::move(console_sink)});

    quill::Backend::stop(); // <-- without this call the segfault is logged correctly and the segfault propagates
    
    char *p {nullptr};
    *p = 1;
}

Expected Behaviour
I would expect the program to segfault without any further log messages. (Does Backend::stop() just need to unregister the signal handler?)

Environment Details

  • Library Version: 11.1.0
  • Operating System: Rocky Linux 9.6
  • Compiler: g++ (GCC) 14.2.1 20250110 (Red Hat 14.2.1-12)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions