Mir

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

Proposed by Daniel van Vugt on 2015-06-23
Status: Merged
Approved by: Daniel van Vugt on 2015-06-25
Approved revision: 2705
Merged at revision: 2701
Proposed branch: lp:~vanvugt/mir/fix-1391976
Merge into: lp:mir
Prerequisite: lp:~vanvugt/mir/test-1391976
Diff against target: 54 lines (+13/-5)
3 files modified
src/protobuf/CMakeLists.txt (+1/-1)
src/protobuf/google_protobuf_guard.cpp (+9/-0)
tests/loader-tests/CMakeLists.txt (+3/-4)
To merge this branch: bzr merge lp:~vanvugt/mir/fix-1391976
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve on 2015-06-25
Robert Carr (community) Approve on 2015-06-24
Kevin DuBois (community) Approve on 2015-06-23
Alexandros Frantzis (community) 2015-06-23 Approve on 2015-06-23
Review via email: mp+262678@code.launchpad.net

Commit Message

Fix^H^H^H Work around protobuf reload issues so that it's always safe
to un/reload libmirprotobuf multiple times. (LP: #1391976)

Technically a proper fix will come from libprotobuf itself but this way
we don't need to wait for that.

Description of the Change

I expect CI might reject this reporting leaks. I'll get to that and add any suppressions required tomorrow.

To post a comment you must log in.
Alexandros Frantzis (afrantzis) wrote :

OK as a workaround, although I feel slightly uncomfortable since it's not expected for libraries to forcibly keep other libraries in memory.

I am working on the proper fix on the protobuf side, which is to ensure libprotobuf doesn't export unnecessary symbols.

review: Approve
Kevin DuBois (kdub) wrote :

Alright (and can't think of a better way to do this, short of going upstream)

review: Approve
Daniel van Vugt (vanvugt) wrote :

It's actually logically perfectly safe. Because already, no function can ever assume there's not some other function in the same process that has loaded and is using the same libraries as itself.

The requirement that modules share the same process and that you can never know the internal reference count of a dl-opened library is pre-existing.

Alberto Aguirre (albaguirre) wrote :

Un TA'ed as pre-req failed autolanding

Robert Carr (robertcarr) wrote :

Sad but reasonable

review: Approve
lp:~vanvugt/mir/fix-1391976 updated on 2015-06-25
2705. By Daniel van Vugt on 2015-06-25

Merge latest parent branch (and trunk)

Daniel van Vugt (vanvugt) wrote :

More sad that this is not the first time I've used this workaround. I've had to do it in previous jobs too and on other Unixes.

The CI failures appear to be unrelated infrastructure faults. The first Jenkins run passed...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/protobuf/CMakeLists.txt'
2--- src/protobuf/CMakeLists.txt 2015-06-17 05:20:42 +0000
3+++ src/protobuf/CMakeLists.txt 2015-06-25 03:55:46 +0000
4@@ -21,7 +21,7 @@
5
6 target_link_libraries(
7 mirprotobuf
8-
9+ dl
10 ${PROTOBUF_LIBRARIES}
11 )
12
13
14=== modified file 'src/protobuf/google_protobuf_guard.cpp'
15--- src/protobuf/google_protobuf_guard.cpp 2013-04-24 05:22:20 +0000
16+++ src/protobuf/google_protobuf_guard.cpp 2015-06-25 03:55:46 +0000
17@@ -20,6 +20,7 @@
18
19 #include <google/protobuf/descriptor.h>
20 #include <mutex>
21+#include <dlfcn.h>
22
23 namespace mir
24 {
25@@ -30,6 +31,14 @@
26
27 void init_google_protobuf()
28 {
29+ // Leak libmirprotobuf.so.X
30+ // This will stop it getting unloaded/reloaded and work around LP: #1391976
31+ Dl_info self;
32+ if (dladdr(reinterpret_cast<void*>(&init_google_protobuf), &self))
33+ {
34+ dlopen(self.dli_fname, RTLD_LAZY | RTLD_NODELETE);
35+ }
36+
37 GOOGLE_PROTOBUF_VERIFY_VERSION;
38 }
39
40
41=== modified file 'tests/loader-tests/CMakeLists.txt'
42--- tests/loader-tests/CMakeLists.txt 2015-06-25 03:55:46 +0000
43+++ tests/loader-tests/CMakeLists.txt 2015-06-25 03:55:46 +0000
44@@ -28,7 +28,6 @@
45
46 target_link_libraries(mir_test_reload_protobuf dl)
47
48-# FIXME: Enable this test after LP: #1391976 is fixed.
49-#add_test(NAME Protobuf-can-be-reloaded # LP: #1391976
50-# COMMAND ${CMAKE_BINARY_DIR}/bin/mir_test_reload_protobuf
51-#)
52+add_test(NAME Protobuf-can-be-reloaded # LP: #1391976
53+ COMMAND ${CMAKE_BINARY_DIR}/bin/mir_test_reload_protobuf
54+)

Subscribers

People subscribed via source and target branches