Skip to content

Reproducible Deadlock #4047

Open
Open
@LiterallyVoid

Description

@LiterallyVoid

For a long time now, Waybar has been occasionally deadlocking. The root cause is that Waybar's signal handlers, defined here:

Waybar/src/main.cpp

Lines 77 to 101 in 056295c

std::signal(SIGUSR1, [](int /*signal*/) {
for (auto& bar : waybar::Client::inst()->bars) {
bar->toggle();
}
});
std::signal(SIGUSR2, [](int /*signal*/) {
spdlog::info("Reloading...");
reload = true;
waybar::Client::inst()->reset();
});
std::signal(SIGINT, [](int /*signal*/) {
spdlog::info("Quitting.");
reload = false;
waybar::Client::inst()->reset();
});
for (int sig = SIGRTMIN + 1; sig <= SIGRTMAX; ++sig) {
std::signal(sig, [](int sig) {
for (auto& bar : waybar::Client::inst()->bars) {
bar->handleSignal(sig);
}
});
}

are not async-signal-safe.

Very few standard library functions are async-signal-safe (in C and in C++). Notably, memory allocation (as used here:

style->remove_class("mode-"s + last_mode_);
) is NOT async-signal-safe.

The deadlock can be reproduced by toggling the bar (by sending SIGUSR1) very fast. I used this shell script:

while true; do killall -SIGUSR1 waybar; done

On my computer, this deadlocks Waybar within 15 seconds, and spamming my "toggle bar" hotkey generally reduced this to 5 seconds.

Potentially related to #348

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions