thrift-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <>
Subject [jira] [Commented] (THRIFT-3891) TNonblockingServer configured with more than one IO threads does not always return from serve() upon stop()
Date Wed, 25 Jan 2017 05:34:26 GMT


ASF GitHub Bot commented on THRIFT-3891:

Github user bgedik commented on a diff in the pull request:
    --- Diff: lib/cpp/src/thrift/server/TNonblockingServer.cpp ---
    @@ -1524,7 +1532,7 @@ void TNonblockingIOThread::breakLoop(bool error) {
       // sets a flag so that the loop exits on the next event
    -  event_base_loopbreak(eventBase_);
    +  event_base_loopexit(eventBase_, 0);
    --- End diff --
    There are some subtle differences between the two. The first difference is what you already
mentioned. The second difference is that, event_base_loopbreak will have no effect when there
is no loop running: In contrast,
event_base_loopexit is not `lost` if it is called without having a loop running.
    In the TNonblockingServer code, event_base_loopbreak is called without checking if the
loop started running.
    An alternative fix would be to keep the event_base_loopbreak, but somehow introduce additional
synchronization to make sure it is not lost.

> TNonblockingServer configured with more than one IO threads does not always return from
serve() upon stop()
> -----------------------------------------------------------------------------------------------------------
>                 Key: THRIFT-3891
>                 URL:
>             Project: Thrift
>          Issue Type: Bug
>          Components: C++ - Library
>    Affects Versions: 0.9.3
>            Reporter: Buğra Gedik
>            Priority: Minor
>         Attachments: patch.diff
> Using {{TNonblockingServer}}, when the number of IO threads is > 1, there is race
condition in which {{stop()}} does not properly unblock {{serve()}}. 
> The problem manifests itself when {{stop()}} is called (obviously from a different thread)
soon after {{serve()}}. 
> The core issue is that, {{event_base_loopbreak()}} is called within the {{stop()}} sequence
without checking whether the IO thread has actually entered its event loop. The documentation
of {{event_base_loopbreak()}} says (
> {quote}
> Note also that event_base_loopexit(base,NULL) and event_base_loopbreak(base) act differently
when no event loop is running: loopexit schedules the next instance of the event loop to stop
right after the next round of callbacks are run (as if it had been invoked with EVLOOP_ONCE)
whereas loopbreak only stops a currently running loop, and has no effect if the event loop
isn’t running.
> {quote}
> Attached is a patch (against the released 0.9.3 version of the codebase).

This message was sent by Atlassian JIRA

View raw message