New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix throwing exceptions from MThreads, plus add unit tests #5803

Merged
merged 4 commits into from Oct 10, 2017

Conversation

Projects
None yet
2 participants
@ahupowerdns
Member

ahupowerdns commented Oct 10, 2017

Short description

In MTasker, MThreads can throw exceptions, which then get caught by the 'kernel' thread. This mechanism was faulty in our 'old boost' support, leading to crashes in std::rethrow_exception.
This PR fixes the 'old boost' support, plus adds a testcase for throwing & catching such exceptions. In addition, this simple testcase found a bug in MTasker with timeoutless waiters. This has also been solved.

Checklist

I have:

  • read the CONTRIBUTING.md document
  • compiled and tested this code
  • included documentation (including possible behaviour changes)
  • documented the code
  • added or modified regression test(s)
  • added or modified unit test(s)
  • checked that this code was merged to master

@ahupowerdns ahupowerdns requested a review from rgacogne Oct 10, 2017

ahupowerdns added some commits Oct 10, 2017

Fix crash on older boost when receiving an exception from an MThread
for older boost fcontext versions, we would return a boolean that said 'we
caught an exception for you and stored it in ctx', but we would not actually
retrieve the origin ctx, and then blindly attempt to rethrow the exception
(not) stored in the ctx we did have, leading to a crash. We now send back the
actual ctx, and check it for a stored exception.
Show outdated Hide outdated pdns/recursordist/test-mtasker.cc Outdated
Show outdated Hide outdated pdns/recursordist/Makefile.am Outdated
auto origctx = reinterpret_cast<pdns_ucontext_t*>(ptr);
if(origctx && origctx->exception)
std::rethrow_exception (origctx->exception);

This comment has been minimized.

@rgacogne

rgacogne Oct 10, 2017

Member

So, I understand why your fix works but I don't get why this didn't work in the first place. Shouldn't origctx be equal to ctx here, after jump_fcontext() returns, or am I getting this backward once again?

@rgacogne

rgacogne Oct 10, 2017

Member

So, I understand why your fix works but I don't get why this didn't work in the first place. Shouldn't origctx be equal to ctx here, after jump_fcontext() returns, or am I getting this backward once again?

This comment has been minimized.

@ahupowerdns

ahupowerdns Oct 10, 2017

Member

so I tried that first, and printed the addresses of 'ctx', and they are different from the address of ctx in the MThread. I tried ctx and octx both. I admit this is somewhat of a "montecarlo programming" fix. There is a little bit of a dance around what 'ctx' means, and even the new boost code has to do some work to extract the ctx we returned from. Perhaps you don't know that when you do the jump_fcontext?

@ahupowerdns

ahupowerdns Oct 10, 2017

Member

so I tried that first, and printed the addresses of 'ctx', and they are different from the address of ctx in the MThread. I tried ctx and octx both. I admit this is somewhat of a "montecarlo programming" fix. There is a little bit of a dance around what 'ctx' means, and even the new boost code has to do some work to extract the ctx we returned from. Perhaps you don't know that when you do the jump_fcontext?

This comment has been minimized.

@rgacogne

rgacogne Oct 10, 2017

Member

Ah yes, I remember something like that, we can have different pdns_ucontext_t and of course the fcontext_t keeps changing.

@rgacogne

rgacogne Oct 10, 2017

Member

Ah yes, I remember something like that, we can have different pdns_ucontext_t and of course the fcontext_t keeps changing.

auto origctx = reinterpret_cast<pdns_ucontext_t*>(ptr);
if(origctx && origctx->exception)
std::rethrow_exception (origctx->exception);

This comment has been minimized.

@rgacogne

rgacogne Oct 10, 2017

Member

Ah yes, I remember something like that, we can have different pdns_ucontext_t and of course the fcontext_t keeps changing.

@rgacogne

rgacogne Oct 10, 2017

Member

Ah yes, I remember something like that, we can have different pdns_ucontext_t and of course the fcontext_t keeps changing.

@ahupowerdns ahupowerdns merged commit 2b55d75 into PowerDNS:master Oct 10, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment