This is an archive of the discontinued LLVM Phabricator instance.

[asan] Fix a deadlock halt_on_error-signals.c when `reporting_thread_tid_` is 0
ClosedPublic

Authored by kubamracek on May 23 2016, 8:11 AM.

Details

Summary

On one of our bots, I'm seeing a deadlock in the halt_on_error-signals.c ASan test. I debugged the issue and it's a race condition when a signal is delivered after TryLock but before StartReporting in the following code:

explicit ScopedInErrorReport(ReportData *report = nullptr,
                           bool fatal = false) {
  halt_on_error_ = fatal || flags()->halt_on_error;

  if (lock_.TryLock()) {
    StartReporting(report);
    return;
  }
  ...
}

In this case, reporting_thread_tid_ is still 0, because it's never initialized to kInvalidTid, causing the nested call to ScopedInErrorReport to try to acquire the lock in lock_.Lock();. This issue can be reproduced by adding a SleepForMillis(100); call after TryLock but before StartReporting. The the test deadlocks every time.

Fixing this by statically initializing reporting_thread_tid_ to kInvalidTid.

Diff Detail

Repository
rL LLVM

Event Timeline

kubamracek updated this revision to Diff 58097.May 23 2016, 8:11 AM
kubamracek retitled this revision from to [asan] Fix a deadlock halt_on_error-signals.c when `reporting_thread_tid_` is 0.
kubamracek updated this object.
kubamracek added a project: Restricted Project.
kubamracek added subscribers: zaks.anna, dcoughlin.

so is this okay to land?

kcc accepted this revision.May 26 2016, 9:42 AM
kcc edited edge metadata.

LGTM

This revision is now accepted and ready to land.May 26 2016, 9:42 AM
This revision was automatically updated to reflect the committed changes.