Mir

Mir client library connection code is not threadsafe

Bug #1183659 reported by Thomi Richards
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mir
Fix Released
High
Alan Griffiths

Bug Description

The mir client library code is supposed to be "thread safe within a single connection" (according to https://lists.ubuntu.com/archives/mir-devel/2013-May/000141.html). However, there is a reasonable amount of code in mir_client_library.cpp that I think is not thread-safe:

The problem is that we're using a global variable 'error_connection' for client connections that have errored. In mir_client_library.cpp, line 40:

MirConnection error_connection;

This then gets used in places like mir_connect (lines 51-74, but with some lines omitted below for clarity):

MirWaitHandle* mir_connect(char const* socket_file, char const* name, mir_connected_callback callback, void * context)
{
    try
    {
        // do some stuff..
        MirConnection* connection = // ...
        return connection->connect( ... );
    }
    catch (std::exception const& x)
    {
        error_connection.set_error_message(x.what());
        return 0;
    }
}

The problem is the set_error_message, the implementation of which is simply:

void MirConnection::set_error_message(std::string const& error)
{
    error_message = error;
}

When trying to connect to the mir server from multiple threads, sometimes more than one thread will try and set the error message at the same time. This causes synchronisation issues, which often causes a double free inside std::string.

It's not enough to make this function thread safe however, we simply cannot use a single global variable to store errored connections.

Related branches

Changed in mir:
importance: Undecided → High
assignee: nobody → Alan Griffiths (alan-griffiths)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

Fix committed into lp:mir at revision None, scheduled for release in mir, milestone 0.0.4

Changed in mir:
status: New → Fix Committed
Changed in mir:
milestone: none → 0.0.4
Changed in mir:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.