Skip to content

Commit

Permalink
Merge pull request #13251 from omoerbeek/mtasker-exception-fiber
Browse files Browse the repository at this point in the history
rec: When an exception is thrown from an mthread register stack switch (in the ASAN case)
  • Loading branch information
omoerbeek authored Sep 13, 2023
2 parents 89209f0 + c3b9a89 commit 7a54e86
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
25 changes: 22 additions & 3 deletions pdns/mtasker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,13 @@ template<class EventKey, class EventVal, class Cmp>int MTasker<EventKey,EventVal
auto userspace=std::move(waiter->context);
d_waiters.erase(waiter); // removes the waitpoint
notifyStackSwitch(d_threads[d_tid].startOfStack, d_stacksize);
pdns_swapcontext(d_kernel,*userspace); // swaps back to the above point 'A'
try {
pdns_swapcontext(d_kernel,*userspace); // swaps back to the above point 'A'
}
catch (...) {
notifyStackSwitchDone();
throw;
}
notifyStackSwitchDone();
return 1;
}
Expand Down Expand Up @@ -325,7 +331,14 @@ template<class Key, class Val, class Cmp>bool MTasker<Key,Val,Cmp>::schedule(con
d_threads[d_tid].dt.start();
#endif
notifyStackSwitch(d_threads[d_tid].startOfStack, d_stacksize);
pdns_swapcontext(d_kernel, *d_threads[d_tid].context);
try {
pdns_swapcontext(d_kernel, *d_threads[d_tid].context);
}
catch (...) {
notifyStackSwitchDone();
// It is not clear if the d_runQueue.pop() should be done in this case
throw;
}
notifyStackSwitchDone();

d_runQueue.pop();
Expand Down Expand Up @@ -367,7 +380,13 @@ template<class Key, class Val, class Cmp>bool MTasker<Key,Val,Cmp>::schedule(con
ttdindex.erase(i++); // removes the waitpoint

notifyStackSwitch(d_threads[d_tid].startOfStack, d_stacksize);
pdns_swapcontext(d_kernel, *uc); // swaps back to the above point 'A'
try {
pdns_swapcontext(d_kernel, *uc); // swaps back to the above point 'A'
}
catch (...) {
notifyStackSwitchDone();
throw;
}
notifyStackSwitchDone();
}
else if(i->ttd.tv_sec)
Expand Down
15 changes: 0 additions & 15 deletions pdns/recursordist/test-mtasker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,6 @@ BOOST_AUTO_TEST_CASE(test_AlmostStackOverflow)
BOOST_CHECK_EQUAL(g_result, o);
}

#if defined(HAVE_FIBER_SANITIZER) && defined(__APPLE__) && defined(__arm64__)

// This test is buggy on MacOS when compiled with asan. It also causes subsequents tests to report spurious issues.
// So switch it off for now
// See https://github.com/PowerDNS/pdns/issues/12151

BOOST_AUTO_TEST_CASE(test_MtaskerException)
{
cerr << "test_MtaskerException test disabled on this platform with asan enabled, please fix" << endl;
}

#else

static void willThrow(void* /* p */)
{
throw std::runtime_error("Help!");
Expand All @@ -111,6 +98,4 @@ BOOST_AUTO_TEST_CASE(test_MtaskerException)
std::exception);
}

#endif // defined(HAVE_FIBER_SANITIZER) && defined(__APPLE__) && defined(__arm64__)

BOOST_AUTO_TEST_SUITE_END()
2 changes: 2 additions & 0 deletions pdns/recursordist/test-rec-zonetocache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ static void zonemdGenericTest(const std::string& lines, pdns::ZoneMD::Config mod
BOOST_AUTO_TEST_CASE(test_zonetocachegeneric)
{
g_log.setLoglevel(Logger::Critical);
g_log.toConsole(Logger::Critical);
zonemdGenericTest(genericTest, pdns::ZoneMD::Config::Require, pdns::ZoneMD::Config::Ignore, 4U);
zonemdGenericTest(genericBadTest, pdns::ZoneMD::Config::Require, pdns::ZoneMD::Config::Ignore, 0U);
}
Expand Down

0 comments on commit 7a54e86

Please sign in to comment.