Skip to content

Potential deadlock in rx-runloop #487

@iam

Description

@iam

While inspecting rx-runloop.hpp I noticed there might be a potential deadlock in the code:

virtual void schedule(clock_type::time_point when, const schedulable& scbl) const {
if (scbl.is_subscribed()) {
auto st = state.lock();
std::unique_lock<std::mutex> guard(st->lock);
const bool need_earlier_wakeup_notification = st->notify_earlier_wakeup &&
(st->q.empty() || when < st->q.top().when);
st->q.push(detail::run_loop_state::item_type(when, scbl));
st->r.reset(false);
if (need_earlier_wakeup_notification) st->notify_earlier_wakeup(when);
guard.unlock(); // So we can't get attempt to recursively lock the state
}
}

Last two lines appear to be flipped, guard.unlock() is a no-op if it's at the end of a scope. During notify_earlier_wakeup it could call back into the runloop and take another lock which would hang since these locks aren't recursive.

/***/           if (need_earlier_wakeup_notification) st->notify_earlier_wakeup(when);
/***/           guard.unlock(); // So we can't get attempt to recursively lock the state

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions