You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2016/11/10 21:26:58 UTC

[jira] [Commented] (THRIFT-3932) C++ ThreadManager has a rare termination race

    [ https://issues.apache.org/jira/browse/THRIFT-3932?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15655192#comment-15655192 ] 

ASF GitHub Bot commented on THRIFT-3932:
----------------------------------------

Github user jeking3 commented on the issue:

    https://github.com/apache/thrift/pull/1103
  
    I decided to leave setDetached and not deprecate it.  I don't see a reason for someone to change from detachable to joinable (or the reverse) while running but I believe all of the servers will properly support it because all three join implementations check if the thread is detached_.  Therefore I am doing a force push on this one and rebased it on master as of earlier today.  Please check it and let me know if there are any more concerns; since we're getting into the beginning of 0.11.0 development I want to get it in as early as possible to get as much soak time as possible, given the area of work.


> C++ ThreadManager has a rare termination race
> ---------------------------------------------
>
>                 Key: THRIFT-3932
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3932
>             Project: Thrift
>          Issue Type: Bug
>          Components: C++ - Library
>            Reporter: Buğra Gedik
>            Assignee: James E. King, III
>             Fix For: 0.11.0
>
>         Attachments: thrift-patch
>
>          Time Spent: 17h
>  Remaining Estimate: 0h
>
> {{ThreadManger::join}} calls {{stopImpl(true)}}, which in turn calls {{removeWorker(workerCount_);}}. The latter waits until {{while (workerCount_ != workerMaxCount_)}}. Within the {{run}} method of the workers, the last thread that detects {{workerCount_ == workerMaxCount_}} notifies {{removeWorker}}. The {{run}} method has the following additional code that is executed at the very end:
> {code}
>     {
>       Synchronized s(manager_->workerMonitor_);
>       manager_->deadWorkers_.insert(this->thread());
>       if (notifyManager) {
>         manager_->workerMonitor_.notify();
>       }
>     }
> {code}
> This is an independent synchronized block. Now assume 2 threads. One of them has {{notifyManager=true}} as it detected the {{workerCount_ == workerMaxCount_}} condition earlier. It is possible that this thread gets to execute  the above code block first, {{ThreadManager}}'s {{removeWorker}} method unblocks, and eventually {{ThreadManager}}'s {{join}} returns and the object is destructed. When the other thread reaches the synchronized block above, it will crash, as the manager is not around anymore.
> Besides, {{ThreadManager}} never joins its threads.
> Attached is a patch.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)