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:
faumarayandClaude Fable 5 committed 2026-07-11 23:46:21 +03:00
1 parent ee4486e1d2
commit a06f639393
4 files changed
+80 -12

No files matched your search

+28
View File
@@ -215,6 +215,34 @@ Void::Testing::Test manager_unload_drops_entry_but_pinned_handle_survives()
Void::Testing::expect_eq(stateful(pinned)->counter(), 1);
}
Void::Testing::Test manager_copy_on_load_survives_in_place_overwrite()
{
Void::FileSystem::TempDir tmp{"void_mgr"};
const auto so = tmp.path() / "plugin.so";
std::filesystem::copy_file(VOID_STATEFUL_V1_PATH, so);
PluginManager mgr{{.copy_on_load = true}};
Void::Testing::expect(mgr.load(so).has_value());
auto h = mgr.acquire("StatefulPlugin");
stateful(h)->bump();
// Overwrite the original file IN PLACE (what a build does). With
// copy_on_load the mapped image is a private unlinked copy, so the
// running instance is unaffected.
std::filesystem::copy_file(
VOID_STATEFUL_V2_PATH, so,
std::filesystem::copy_options::overwrite_existing);
Void::Testing::expect_eq(stateful(h)->schema_version(), 1);
Void::Testing::expect_eq(stateful(h)->counter(), 1);
// Reload still tracks the original path and picks up the new bytes.
Void::Testing::expect(mgr.reload("StatefulPlugin").has_value());
auto fresh = mgr.acquire("StatefulPlugin");
Void::Testing::expect_eq(stateful(fresh)->schema_version(), 2);
Void::Testing::expect_eq(stateful(fresh)->counter(), 1);
}
Void::Testing::Test manager_state_snapshot_round_trip()
{
PluginManager mgr;