Plugin: copy_on_load option; unique hotswap temp names
- copy_on_load: dlopen a fresh-inode temp copy on first load (reloads already did), so deployments that rewrite the plugin file in place — e.g. a build writing its output — cannot corrupt the mapped image. The registry keeps addressing the original path for watch/reload. - hotswap_copy now generates a unique temp name per copy. glibc dedupes dlopen by pathname, so the previous fixed ".void_hotswap" name made every second reload through the same path silently return the already-mapped OLD image instead of the new bytes. - hot_reload_under_concurrent_load now asserts the true downgrade semantics (v2 -> v1 is rejected transactionally, v2 stays); it only ever passed the old all-succeed expectation via the dedup bug, since no flip after the first actually took effect. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018yj92cCihyaYtf4gKCT3nv
This commit is contained in:
1 parent
ee4486e1d2
commit
a06f639393
4 files changed
+80
-12
No files matched your search
@@ -1,3 +1,4 @@
|
||||
#include <Void/Plugin/Loader.hpp>
|
||||
#include <Void/Plugin/Manager.hpp>
|
||||
#include <Void/System/TempDir.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
@@ -78,13 +79,23 @@ Void::Testing::Test hot_reload_under_concurrent_load()
|
||||
});
|
||||
}
|
||||
|
||||
// Main thread flips the file v1<->v2 and reloads repeatedly.
|
||||
// Main thread flips the file v1<->v2 and reloads repeatedly. The first
|
||||
// v2 reload migrates v1 state forward; after that, installing v1 is a
|
||||
// DOWNGRADE — v1 cannot deserialize v2 state, so the transactional
|
||||
// reload must fail with StateRejected and keep the v2 instance. (An
|
||||
// earlier version of this test expected every reload to succeed; that
|
||||
// only passed because a fixed hotswap temp name made dlopen return the
|
||||
// already-mapped image, so no flip after the first ever took effect.)
|
||||
for (int i = 0; i < 24; ++i) {
|
||||
const char* src =
|
||||
(i % 2 == 0) ? VOID_STATEFUL_V2_PATH : VOID_STATEFUL_V1_PATH;
|
||||
install(src, so);
|
||||
const bool to_v2 = (i % 2 == 0);
|
||||
install(to_v2 ? VOID_STATEFUL_V2_PATH : VOID_STATEFUL_V1_PATH, so);
|
||||
const auto r = mgr.reload("StatefulPlugin");
|
||||
Void::Testing::expect(r.has_value());
|
||||
if (to_v2) {
|
||||
Void::Testing::expect(r.has_value());
|
||||
} else {
|
||||
Void::Testing::expect(!r.has_value());
|
||||
Void::Testing::expect(r.error() == LoadError::StateRejected);
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{2});
|
||||
}
|
||||
|
||||
@@ -97,12 +108,14 @@ Void::Testing::Test hot_reload_under_concurrent_load()
|
||||
Void::Testing::expect_eq(crashes.load(), 0);
|
||||
Void::Testing::expect(ops.load() > 0);
|
||||
|
||||
// State survived every migration: the final instance's counter is at
|
||||
// least the number of reloads' worth of preserved bumps (monotonic,
|
||||
// never reset to zero by a swap).
|
||||
// State survived every migration: the counter is monotonic, never
|
||||
// reset by a swap, and the surviving instance is the v2 build (every
|
||||
// attempted downgrade was rejected transactionally).
|
||||
auto final = mgr.acquire("StatefulPlugin");
|
||||
Void::Testing::expect(static_cast<bool>(final));
|
||||
Void::Testing::expect(VoidTest::as_stateful(final.get())->counter() > 0);
|
||||
Void::Testing::expect_eq(
|
||||
VoidTest::as_stateful(final.get())->schema_version(), 2);
|
||||
}
|
||||
|
||||
#endif // stateful plugins available
|
||||
Reference in new issue
Block a user