Skip to content
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

Changes wrt recent crashes of nodes #165

Merged
merged 10 commits into from
Sep 21, 2019

Conversation

pmconrad
Copy link

@pmconrad pmconrad commented Sep 16, 2019

* added some safety for openssl type wrappers, just in case (moved to #166)

  • replaced spin_yield_lock in promise_base with atomic to avoid yielding in an exception handler

@abitmore abitmore added this to the core release 4.1.0 milestone Sep 16, 2019
Copy link
Member

@abitmore abitmore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think it's better to split the openssl and socket changes to another PR.
  2. It seems the _spin_yield_lock was there to ensure consistency of multiple members in a promise_base object, although not all members are protected at all times. This PR changed the behavior to mostly only try to protect individual members. Is it safe?
  3. std::atomic is working on the threading layer but not the tasking layer, so it seems the new code will wait when unable to obtain a lock but will not yield to another task. A question is whether it will lead to deadlock or starvation. I guess the answer is no, because the lock would be being held by another thread and will be released fast enough, so won't matter if current task in current thread need to wait for a while.

_blocked_thread = &thread::current();
do
assert( !blocked_thread || blocked_thread == &thread::current() );
while( !_blocked_thread.compare_exchange_weak( blocked_thread, &thread::current() ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks suspicious, although the old behavior is kept. It guarantees that _blocked_thread will be replaced by current thread, but in release build assert(...) will be dropped, so _blocked_thread could be replaced by another thread when it's already set.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a brief attempt to improve it but didn't succeed, then decided to keep the old behaviour.

@pmconrad
Copy link
Author

This PR changed the behavior to mostly only try to protect individual members. Is it safe?

I'm pretty sure, yes. The only two places where the spin_yield_lock protected more than one member are at the beginning of _wait_until and in _dequeue_thread. In _wait_until I added another check on _ready after the _enqueue_thread in case the thread missed a notify(). _dequeue_thread is only ever called by the _blocked_thread so protection is not really needed anyway.

A question is whether it will lead to deadlock or starvation.

No. Note that with a modern compiler and hardware atomic should be lock-free. Even if it is not, there is only one lock active at a time, so there can be no deadlock. Also, threads don't yield while holding the lock, so a lock held by another task will not be a problem.

@pmconrad
Copy link
Author

I think it's better to split the openssl and socket changes to another PR.

Done -> #166

@abitmore abitmore changed the base branch from master to for-core-3-3 September 18, 2019 12:15
@abitmore
Copy link
Member

@pmconrad for easier to test, please rebase to for-core-3-3. Thanks!

@pmconrad
Copy link
Author

Rebased

@pmconrad
Copy link
Author

Added a fix for zero-initialization of std::array<unsigned char,N>

Copy link
Member

@abitmore abitmore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code in 020a37e itself looks fine. I didn't check whether there are other instances where std::array is used though. Update: I've checked.

Copy link
Member

@abitmore abitmore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants