5.2.23
12/09/2023

[#254] RosterManager::synchronize() is not thread safe!
Summary RosterManager::synchronize() is not thread safe!
Queue gloox
Queue Version 1.0.13
Type Bug
State Unconfirmed
Priority 3. High
Owners
Requester matias.snellingen (at) outlook (dot) com
Created 08/17/2015 (3036 days ago)
Due
Updated 08/17/2015 (3036 days ago)
Assigned
Resolved

History
08/17/2015 11:21:06 AM matias (dot) snellingen (at) outlook (dot) com Comment #1
State ⇒ Unconfirmed
Priority ⇒ 3. High
Type ⇒ Bug
Summary ⇒ RosterManager::synchronize() is not thread safe!
Queue ⇒ gloox
Reply to this comment
If you do:

// remove first roster item
auto first_item_jid = jabber.rosterManager()->roster()->begin()->first;
jabber.rosterManager()->remove(first_item_jid);
jabber.rosterManager()->synchronize();

// this code will crash since iterators are invalidated by 
gloox::Client::connect thread
for (auto roster_item : *jabber.rosterManager()->roster())
{
        // simulate spending some time on each roster item
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

The for each loop will crash even if it does not do any write operation.
And based on https://camaya.net/gloox/faq/#threadsafety, it should not?