Skip to content

[TSAN] Use only async signal safe functions in signal handlers#2131

Merged
wezrule merged 4 commits intonanocurrency:masterfrom
wezrule:tsan_signals_daemon
Jul 10, 2019
Merged

[TSAN] Use only async signal safe functions in signal handlers#2131
wezrule merged 4 commits intonanocurrency:masterfrom
wezrule:tsan_signals_daemon

Conversation

@wezrule
Copy link
Copy Markdown
Contributor

@wezrule wezrule commented Jul 5, 2019

Very little is allowed in signal handlers, specifically only async-signal-safe functions. This is because code can be halted at any point, if a mutex is already locked elsewhere for instance this will result in deadlock. TSAN gives many warnings when closing the daemon when the SIGTERM/SIGINT and SIGSEGV signals are raised. Instead of calling our application specific code in the signal handler I just stop the io_context (which is done in a few asio examples), the rest of the cleanup code is now done by checking a sigatomic_t variable after the asio loop has finished.

Now also using specific Linux file descriptor commands which are known to be async-signal-safe (looked at how the boost stacktrace dump does it as it states signal safety) in the segfault/abort signal handler.

(Unrelated) I noticed 2 places where there was an unnamed std::lock_guard being used.

@wezrule wezrule added the sanitizers Related to thread, address or undefined sanitizers label Jul 5, 2019
@wezrule wezrule self-assigned this Jul 5, 2019
@wezrule wezrule force-pushed the tsan_signals_daemon branch from 5bc2fb5 to 8352a64 Compare July 5, 2019 16:33
@wezrule wezrule force-pushed the tsan_signals_daemon branch from 8352a64 to c8f4563 Compare July 5, 2019 16:38
@wezrule wezrule added this to the V19.0 milestone Jul 7, 2019
@wezrule wezrule merged commit 656650b into nanocurrency:master Jul 10, 2019
@wezrule wezrule deleted the tsan_signals_daemon branch July 10, 2019 16:05
argakiig pushed a commit that referenced this pull request Jul 10, 2019
* Use only async-signal-safe functions in signal handlers

* Fix load-tester race

* Use consistent code when outputting load addresses
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sanitizers Related to thread, address or undefined sanitizers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants