Mir

Merge lp:~vanvugt/mir/fix-1358191 into lp:mir

Proposed by Daniel van Vugt
Status: Rejected
Rejected by: Daniel van Vugt
Proposed branch: lp:~vanvugt/mir/fix-1358191
Merge into: lp:mir
Diff against target: 41 lines (+17/-2)
1 file modified
src/client/mir_connection_api.cpp (+17/-2)
To merge this branch: bzr merge lp:~vanvugt/mir/fix-1358191
Reviewer Review Type Date Requested Status
Alan Griffiths Disapprove
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+232062@code.launchpad.net

Commit message

Avoid confusing weak/shared pointer ownership. In the case that
connect() fails and throws an exception, make sure the shared_ptr to your
ClientPlatformFactory (inside MirConnection) lives longer than the original
weak_ptr to it (inside conf). If you let the shared_ptr destruct first in
this case, the weak_ptr it came from somehow loses track and tries to
delete the object a second time, hence crashing (LP: #1358191)

Description of the change

Unfortunately testing this fix is hit and miss. For several hours today I could reproduce the bug reliably and verified this proposal does fix it. Other times (like all of Friday and now this evening) the bug stops happening so you can't be sure at all.

If this isn't a compiler bug then I can only assume there are compliant cases where weak_ptr stops communicating properly with shared_ptr's of the same object. I'm not aware of any way C++ allows that intentionally though.

Safe to say I'm still confused by this and hoping someone finds a simpler explanation before I wake up...

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

See https://code.launchpad.net/~afrantzis/mir/fix-1358191-connect-segv-spike/+merge/232108 for an MP that tries to address the core problem behind this bug.

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> See https://code.launchpad.net/~afrantzis/mir/fix-1358191-connect-segv-
> spike/+merge/232108 for an MP that tries to address the core problem behind
> this bug.

That's a better approach

review: Disapprove

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/client/mir_connection_api.cpp'
2--- src/client/mir_connection_api.cpp 2014-08-11 21:56:45 +0000
3+++ src/client/mir_connection_api.cpp 2014-08-25 11:11:24 +0000
4@@ -58,6 +58,8 @@
5 mir_connected_callback callback,
6 void* context) override
7 {
8+ MirConnection* connection = nullptr;
9+
10 try
11 {
12 std::string sock;
13@@ -74,13 +76,26 @@
14
15 auto const conf = configuration(sock);
16
17- std::unique_ptr<MirConnection> connection{new MirConnection(*conf)};
18+ // XXX Beware bug LP: #1358191
19+ // connection must not be a unique or shared pointer object!
20+ // If connect() throws then connection needs to live longer than
21+ // conf. Otherwise connection will delete its
22+ // client_platform_factory and conf's Cached/weak pointers to
23+ // the same factory will somehow remain valid, resulting in
24+ // a second spurious delete of the already deleted object.
25+ // This may be a compiler bug, or maybe the breakdown in
26+ // communication between shared and weak is correct in this
27+ // case. Not sure.
28+ // So long as you let conf destruct first, then everything
29+ // will be OK.
30+ connection = new MirConnection(*conf);
31+
32 auto const result = connection->connect(name, callback, context);
33- connection.release();
34 return result;
35 }
36 catch (std::exception const& x)
37 {
38+ delete connection;
39 MirConnection* error_connection = new MirConnection(x.what());
40 mcl::ErrorConnections::instance().insert(error_connection);
41 callback(error_connection, context);

Subscribers

People subscribed via source and target branches