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

Martin Zlomek commented on PROTON-2792:
---------------------------------------

possible fix:
{code:c++}
void container::impl::run_timer_jobs() {
    std::vector<work> tasks;

    // We first extract all the runnable tasks and then run them -  this is to 
avoid having tasks
    // injected as we are running them (which could potentially never end)
    {
        GUARD(deferred_lock_);

        // Figure out how many tasks we need to execute and pop them to the 
back of the queue
        for (timestamp now = timestamp::now(); deferred_.size() > 0; 
deferred_.pop_back()) {
            // Is the next task in the future?
            timestamp next_time = deferred_.front().time;
            if ( next_time>now ) {
                pn_proactor_set_timeout(proactor_, 
(next_time-now).milliseconds());
                break;
            }

            std::pop_heap(deferred_.begin(), deferred_.end());

            if (is_active_.erase(deferred_.back().w_handle))
                tasks.push_back(std::move(deferred_.back().task));
        }
    }

    // We've now taken the tasks to run from the deferred tasks
    // so we can run them unlocked
    for (work task : tasks) task();
} {code}

> [cpp] Segmentation fault in container::impl::run_timer_jobs
> -----------------------------------------------------------
>
>                 Key: PROTON-2792
>                 URL: https://issues.apache.org/jira/browse/PROTON-2792
>             Project: Qpid Proton
>          Issue Type: Bug
>          Components: cpp-binding
>    Affects Versions: proton-c-0.38.0
>            Reporter: Martin Zlomek
>            Priority: Major
>
> PROTON-2438 introduced a race condition in 
> [reading|https://github.com/DreamPearl/qpid-proton/blob/8142e3cecd9f668992e76a5448afc09fd7b1030a/cpp/src/proactor_container_impl.cpp#L545]
>  / 
> [writing|https://github.com/DreamPearl/qpid-proton/blob/8142e3cecd9f668992e76a5448afc09fd7b1030a/cpp/src/proactor_container_impl.cpp#L547]
>  {{is_active_}} in 
> [{{run_timer_jobs()}}|https://github.com/DreamPearl/qpid-proton/blob/8142e3cecd9f668992e76a5448afc09fd7b1030a/cpp/src/proactor_container_impl.cpp#L498]
>  while modifying it in 
> [{{schedule()}}|https://github.com/DreamPearl/qpid-proton/blob/8142e3cecd9f668992e76a5448afc09fd7b1030a/cpp/src/proactor_container_impl.cpp#L455]
>  or 
> [{{cancel()}}|https://github.com/DreamPearl/qpid-proton/blob/8142e3cecd9f668992e76a5448afc09fd7b1030a/cpp/src/proactor_container_impl.cpp#L473]
>  at the same time.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org
For additional commands, e-mail: dev-h...@qpid.apache.org

Reply via email to