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

Race condition in pplx::task_completion_event #256

Open
mmthomas opened this issue Oct 6, 2016 · 0 comments
Open

Race condition in pplx::task_completion_event #256

mmthomas opened this issue Oct 6, 2016 · 0 comments
Labels

Comments

@mmthomas
Copy link

mmthomas commented Oct 6, 2016

It's possible for two threads to try to complete a task_completion_event at the same time, where one calls set_exception(), and the other calls set().

A problem occurs if the first thread calling _StoreException() (via set_exception()) successfully completes, storing the exception holder, but then the second thread calling set() gets its timeslice before the first thread can call _CancelInternal().

In this case, the call to set() will enter the critical section and set the stack-based _RunContinuations flag to true, which will then subsequently cause the non-empty exception holder to be released. If this is the only reference to the exception holder (set via the first thread), the process will abort in debug builds via _REPORT_PPLTASK_UNOBSERVED_EXCEPTION.

So the possible order of operations is this:

thread1...                          

    set_exception(...)
        _Cancel(...)
            if (_StoreException(...)) // returns true

thread 2...

    set(...)
        ...
        // following call reports unobserved exception, 
        // even though tce is not in a canceled state
        _M_Impl->_M_exceptionHolder.reset(); 

thread 1...      

                // following call returns false, 
                // even though _StoreException() returned true
                _Canceled = _CancelInternal(); 
garethsb added a commit to sony/nmos-cpp that referenced this issue Jun 22, 2018
…ompletion event has already been set; unfortunately I think there's still a race condition in pplx::task_completion_event implementation in a multi-threaded scenario; see microsoft/cpprestsdk#256

(cherry picked from commit 2178a93cb5888af9e7b733e150e2675e2727742f)
@BillyONeal BillyONeal added the bug label Oct 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants