3 Commits
Author SHA1 Message Date
faumaray f94366104e Update
CI / GCC 16 / C++26 / default (pull_request) Has been cancelled
CI / GCC 16 / C++26 / sanitizers (pull_request) Has been cancelled
CI / GCC 16 / C++26 / werror (pull_request) Has been cancelled
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-12 02:37:49 +03:00
faumarayandClaude Fable 5 9a54f15e7e Net: actually enforce Request::timeout on HTTP socket I/O
Request::timeout was declared but never used — every sync Asio
operation (TLS handshake, read, write) blocked without bound, so a
stalled peer hung the calling thread indefinitely (observed: a stalled
CDN download blocking a host's shutdown join forever).

SO_RCVTIMEO cannot fix this: Asio's sync emulation treats the
resulting EAGAIN as would-block and poll()s with no deadline. Instead
a per-request DeadlineGuard watchdog ::shutdown()s the descriptor on
expiry, which wakes any blocked sync op with EOF and fails the
request. Declaration order in send() keeps the descriptor owners alive
past the guard. Resolution and connect() remain on kernel defaults.

Regression test: a stalled localhost server is bounded at ~1s.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018yj92cCihyaYtf4gKCT3nv
2026-07-12 00:20:49 +03:00
faumarayandClaude Fable 5 a06f639393 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
2026-07-11 23:46:21 +03:00
12 changed files with 332 additions and 37 deletions

No files matched your search

+9 -7
View File
@@ -23,13 +23,15 @@ function(void_add_module MODULE_NAME)
add_library(${TGT} INTERFACE)
target_compile_features(${TGT} INTERFACE cxx_std_26)
else()
set(LIB_TYPE "SHARED")
set(SCOPE "PUBLIC")
if (MODULE_NAME STREQUAL "Testing")
add_library(${TGT} STATIC)
else()
add_library(${TGT} SHARED)
endif()
set(SCOPE "PUBLIC")
if (MODULE_NAME STREQUAL "Testing")
add_library(${TGT} STATIC)
else()
# Honour the standard BUILD_SHARED_LIBS policy. Consumers that ship a
# single validated executable must be able to embed Void modules,
# while Void's standalone default remains shared.
add_library(${TGT})
endif()
target_sources(${TGT} PRIVATE ${SRC})
target_compile_features(${TGT} PUBLIC cxx_std_26)
endif()
+2
View File
@@ -17,6 +17,7 @@ enum class LoadError {
CreateFailed,
NotSupported, // platform does not support dlopen
StateRejected, // new instance refused the serialized state
ActivationFailed, // on_load threw or readiness validation failed
UnknownPlugin, // PluginManager: no plugin registered under that name
};
@@ -72,6 +73,7 @@ private:
IPlugin* plugin_ {};
destroy_fn destroy_ {};
transfer_fn transfer_ {};
ready_fn ready_ {};
state_version_fn state_version_{};
serialize_fn serialize_ {};
free_string_fn free_string_ {};
+6
View File
@@ -74,6 +74,12 @@ namespace Void::Plugin
// executing would crash. Pins already prevent the instance from
// being destroyed; this guards the code pages.
bool dlclose_on_swap = false;
// dlopen a fresh-inode temp copy instead of the original file on
// the first load (reloads already do). Turn on when deployments
// overwrite the plugin file in place (e.g. a build writing its
// output) — mapping the original would then corrupt the running
// image (SIGBUS). The registry keeps tracking the original path.
bool copy_on_load = false;
// Per-plugin configuration source. When set, its result is passed
// to the plugin's optional void_plugin_configure entry point after
// create and after each reload swap, before on_load(). The plugin
+8
View File
@@ -55,6 +55,12 @@ public:
// JSON) after create and after each hot-reload swap, before
// on_load(). The string is only valid for the duration of the call.
//
// Optional (transactional activation check):
// int void_plugin_ready(void* instance)
// — called after on_load() and state restoration, immediately before
// the instance becomes visible. Return 0 when the plugin is ready.
// Any other value aborts load/reload and keeps the old instance.
//
// Optional v2 state protocol (preferred over transfer_state when both
// sides provide it; survives layout changes between plugin versions):
//
@@ -74,6 +80,7 @@ using destroy_fn = void (*)(void*);
using info_fn = PluginInfo (*)(void);
using transfer_fn = void (*)(void* old_instance, void* new_instance);
using configure_fn = void (*)(void* instance, const char* config);
using ready_fn = int (*)(void* instance);
using state_version_fn = std::uint32_t (*)(void);
using serialize_fn = const char* (*)(void* instance);
using free_string_fn = void (*)(const char*);
@@ -85,6 +92,7 @@ inline constexpr const char* kDestroySymbol = "void_plugin_destroy";
inline constexpr const char* kInfoSymbol = "void_plugin_info";
inline constexpr const char* kTransferSymbol = "void_plugin_transfer_state";
inline constexpr const char* kConfigureSymbol = "void_plugin_configure";
inline constexpr const char* kReadySymbol = "void_plugin_ready";
inline constexpr const char* kStateVersionSymbol = "void_plugin_state_version";
inline constexpr const char* kSerializeSymbol = "void_plugin_serialize_state";
inline constexpr const char* kFreeStringSymbol = "void_plugin_free_string";
+98 -12
View File
@@ -14,12 +14,21 @@
#include <openssl/ssl.h>
#if !defined(_WIN32)
#include <sys/socket.h>
#include <sys/time.h>
#endif
#include <cctype>
#include <chrono>
#include <condition_variable>
#include <cstdint>
#include <format>
#include <limits>
#include <mutex>
#include <optional>
#include <stdexcept>
#include <thread>
#include <vector>
namespace Void::Net
@@ -227,17 +236,88 @@ namespace Void::Net
stream.handshake(ssl::stream_base::client);
}
// Bounds every sync operation on an open socket with the request
// timeout. Asio's synchronous ops cannot be bounded any other way
// short of going fully async: SO_RCVTIMEO merely makes recv return
// EAGAIN, which the sync emulation treats as would-block and then
// poll()s without a deadline. On expiry the watchdog ::shutdown()s
// the descriptor — shutdown (unlike close) is safe against a
// concurrent blocked op and wakes it with EOF, so the op fails and
// the request errors out instead of hanging the calling thread
// forever. The descriptor must stay open for the guard's lifetime
// (declare the guard after the connected socket, in the same scope).
// Name resolution and connect() are not covered (kernel defaults).
class DeadlineGuard
{
public:
DeadlineGuard(tcp::socket& socket,
std::chrono::seconds timeout)
{
if (timeout <= std::chrono::seconds::zero() ||
!socket.is_open()) {
return;
}
const auto fd = socket.native_handle();
m_worker = std::thread([this, fd, timeout] {
std::unique_lock lock{m_mutex};
if (!m_cv.wait_for(lock, timeout,
[this] { return m_done; })) {
#if defined(_WIN32)
::shutdown(fd, SD_BOTH);
#else
::shutdown(fd, SHUT_RDWR);
#endif
m_timed_out = true;
}
});
}
DeadlineGuard(const DeadlineGuard&) = delete;
DeadlineGuard& operator=(const DeadlineGuard&) = delete;
~DeadlineGuard()
{
if (!m_worker.joinable()) {
return;
}
{
std::lock_guard lock{m_mutex};
m_done = true;
}
m_cv.notify_all();
m_worker.join();
}
[[nodiscard]] bool timed_out() const noexcept
{
return m_timed_out;
}
private:
std::thread m_worker;
std::mutex m_mutex;
std::condition_variable m_cv;
bool m_done{false};
bool m_timed_out{false};
};
// Perform the request over an already-connected plain socket, doing a
// TLS upgrade in place when the target is https.
Response finish(tcp::socket socket, ssl::context& ctx, const Url& url,
const Request& req, std::string_view ua,
std::uint64_t max_body)
// TLS upgrade in place when the target is https. The TLS stream is an
// out-parameter declared in the caller's scope so the descriptor
// outlives the caller's DeadlineGuard (declaration order there is
// socket, stream, guard — the guard is destroyed first).
Response finish(tcp::socket& socket,
std::optional<ssl::stream<tcp::socket>>& tls,
ssl::context& ctx, const Url& url, const Request& req,
std::string_view ua, std::uint64_t max_body)
{
if (url.is_tls) {
ssl::stream<tcp::socket> stream{std::move(socket), ctx};
tls_handshake(stream, url);
tls.emplace(std::move(socket), ctx);
tls_handshake(*tls, url);
auto rq = build_request(url, req, ua, url.target);
return write_read(stream, rq, max_body);
return write_read(*tls, rq, max_body);
}
auto rq = build_request(url, req, ua, url.target);
return write_read(socket, rq, max_body);
@@ -310,19 +390,25 @@ namespace Void::Net
Response response;
tcp::resolver resolver{ioc};
// Declaration order matters: the DeadlineGuard must be
// destroyed (and its watchdog joined) BEFORE the objects
// that own the descriptor it may shut down.
tcp::socket socket{ioc};
std::optional<ssl::stream<tcp::socket>> tls;
if (m_proxy.enabled()) {
tcp::socket socket{ioc};
asio::connect(socket, resolver.resolve(
m_proxy.host,
std::to_string(m_proxy.port)));
DeadlineGuard deadline{socket, req.timeout};
if (m_proxy.kind == ProxyConfig::Kind::Socks5) {
socks5_connect(socket, *url, m_proxy);
response = finish(std::move(socket), ctx, *url, req,
response = finish(socket, tls, ctx, *url, req,
m_user_agent, m_max_body);
} else { // Http proxy
if (url->is_tls) {
http_connect_tunnel(socket, *url, m_proxy);
response = finish(std::move(socket), ctx, *url, req,
response = finish(socket, tls, ctx, *url, req,
m_user_agent, m_max_body);
} else {
// Plain HTTP through proxy: absolute-form target.
@@ -341,10 +427,10 @@ namespace Void::Net
}
}
} else {
tcp::socket socket{ioc};
asio::connect(socket,
resolver.resolve(url->host, url->port));
response = finish(std::move(socket), ctx, *url, req,
DeadlineGuard deadline{socket, req.timeout};
response = finish(socket, tls, ctx, *url, req,
m_user_agent, m_max_body);
}
+23 -4
View File
@@ -23,6 +23,7 @@ std::string_view to_string(LoadError e) noexcept
case LoadError::CreateFailed: return "plugin create() returned null";
case LoadError::NotSupported: return "platform does not support dlopen";
case LoadError::StateRejected: return "new instance rejected state";
case LoadError::ActivationFailed: return "plugin activation failed";
case LoadError::UnknownPlugin: return "no plugin registered under name";
}
return "unknown";
@@ -44,6 +45,7 @@ void PluginLoader::destroy_current() noexcept
}
destroy_ = nullptr;
transfer_ = nullptr;
ready_ = nullptr;
state_version_ = nullptr;
serialize_ = nullptr;
free_string_ = nullptr;
@@ -121,6 +123,7 @@ PluginLoader::load_from(const std::filesystem::path& path)
plugin_ = static_cast<IPlugin*>(raw);
destroy_ = sym_destroy;
transfer_ = reinterpret_cast<transfer_fn>(dlsym(h, kTransferSymbol));
ready_ = reinterpret_cast<ready_fn>(dlsym(h, kReadySymbol));
state_version_ = reinterpret_cast<state_version_fn>(
dlsym(h, kStateVersionSymbol));
serialize_ = reinterpret_cast<serialize_fn>(dlsym(h, kSerializeSymbol));
@@ -153,7 +156,14 @@ PluginLoader::load(std::filesystem::path path)
return std::unexpected{r.error()};
}
ldr.plugin_->on_load();
try {
ldr.plugin_->on_load();
} catch (...) {
return std::unexpected{LoadError::ActivationFailed};
}
if (ldr.ready_ && ldr.ready_(ldr.plugin_) != 0) {
return std::unexpected{LoadError::ActivationFailed};
}
Void::Log::info("Plugin", "loaded '{}' ({} v{})", path.string(),
ldr.info_.name, ldr.info_.plugin_version);
return ldr;
@@ -166,6 +176,7 @@ PluginLoader::PluginLoader(PluginLoader&& o) noexcept
, plugin_ {std::exchange(o.plugin_, nullptr)}
, destroy_ {std::exchange(o.destroy_, nullptr)}
, transfer_ {std::exchange(o.transfer_, nullptr)}
, ready_ {std::exchange(o.ready_, nullptr)}
, state_version_{std::exchange(o.state_version_, nullptr)}
, serialize_ {std::exchange(o.serialize_, nullptr)}
, free_string_ {std::exchange(o.free_string_, nullptr)}
@@ -182,6 +193,7 @@ PluginLoader& PluginLoader::operator=(PluginLoader&& o) noexcept
plugin_ = std::exchange(o.plugin_, nullptr);
destroy_ = std::exchange(o.destroy_, nullptr);
transfer_ = std::exchange(o.transfer_, nullptr);
ready_ = std::exchange(o.ready_, nullptr);
state_version_ = std::exchange(o.state_version_, nullptr);
serialize_ = std::exchange(o.serialize_, nullptr);
free_string_ = std::exchange(o.free_string_, nullptr);
@@ -228,11 +240,18 @@ std::expected<void, LoadError> PluginLoader::reload()
return std::unexpected{LoadError::StateRejected};
}
// Destroy old, install new.
try {
next.plugin_->on_load();
} catch (...) {
return std::unexpected{LoadError::ActivationFailed};
}
if (next.ready_ && next.ready_(next.plugin_) != 0) {
return std::unexpected{LoadError::ActivationFailed};
}
// Activation succeeded; only now destroy old and install new.
destroy_current();
*this = std::move(next);
plugin_->on_load();
Void::Log::info("Plugin", "reloaded '{}' ({} v{})", path_.string(),
info_.name, info_.plugin_version);
+48 -6
View File
@@ -8,7 +8,9 @@
#endif
#include <algorithm>
#include <atomic>
#include <cstdint>
#include <string>
#include <system_error>
#include <utility>
@@ -23,6 +25,7 @@ namespace Void::Plugin
destroy_fn destroy{nullptr};
transfer_fn transfer{nullptr};
configure_fn configure{nullptr};
ready_fn ready{nullptr};
state_version_fn state_version{nullptr};
serialize_fn serialize{nullptr};
free_string_fn free_string{nullptr};
@@ -119,6 +122,8 @@ namespace Void::Plugin
reinterpret_cast<transfer_fn>(dlsym(h, kTransferSymbol));
inst->configure =
reinterpret_cast<configure_fn>(dlsym(h, kConfigureSymbol));
inst->ready =
reinterpret_cast<ready_fn>(dlsym(h, kReadySymbol));
inst->state_version = reinterpret_cast<state_version_fn>(
dlsym(h, kStateVersionSymbol));
inst->serialize =
@@ -170,12 +175,18 @@ namespace Void::Plugin
}
// Copy to a fresh-inode temp path so dlopen does not return the
// already-mapped image when the file is replaced in place.
// already-mapped image when the file is replaced in place. The name
// must be unique per copy: glibc dedupes dlopen by pathname, so
// reusing a temp name would hand back the previously mapped (old)
// image no matter what bytes the file now holds.
std::expected<std::filesystem::path, LoadError>
hotswap_copy(const std::filesystem::path& path)
{
const auto tmp = path.parent_path() /
(path.filename().string() + ".void_hotswap");
static std::atomic<std::uint64_t> counter{0};
const auto tmp =
path.parent_path() /
(path.filename().string() + ".void_hotswap." +
std::to_string(counter.fetch_add(1, std::memory_order_relaxed)));
std::error_code ec;
std::filesystem::copy_file(
path, tmp, std::filesystem::copy_options::overwrite_existing,
@@ -211,7 +222,20 @@ namespace Void::Plugin
if (!std::filesystem::exists(path, ec)) {
return std::unexpected{LoadError::FileNotFound};
}
auto inst = open_instance(path, m_options.dlclose_on_swap);
std::filesystem::path load_path = path;
if (m_options.copy_on_load) {
auto tmp = hotswap_copy(path);
if (!tmp.has_value()) {
return std::unexpected{tmp.error()};
}
load_path = *tmp;
}
auto inst = open_instance(load_path, m_options.dlclose_on_swap);
if (m_options.copy_on_load) {
// The mapping keeps the unlinked inode alive; the registry
// keeps addressing the original path for watch/reload.
std::filesystem::remove(load_path, ec);
}
if (!inst.has_value()) {
Void::Log::warn("Plugin.Manager", "load '{}' failed: {}",
path.string(), to_string(inst.error()));
@@ -222,7 +246,15 @@ namespace Void::Plugin
const std::string config = m_options.config_provider(name);
(*inst)->configure((*inst)->plugin, config.c_str());
}
(*inst)->plugin->on_load();
try {
(*inst)->plugin->on_load();
} catch (...) {
return std::unexpected{LoadError::ActivationFailed};
}
if ((*inst)->ready != nullptr &&
(*inst)->ready((*inst)->plugin) != 0) {
return std::unexpected{LoadError::ActivationFailed};
}
std::lock_guard lock(m_mutex);
auto entry = std::make_unique<Entry>();
@@ -351,7 +383,17 @@ namespace Void::Plugin
}
}
(*next)->plugin->on_load();
try {
(*next)->plugin->on_load();
} catch (...) {
return std::unexpected{LoadError::ActivationFailed};
}
if ((*next)->ready != nullptr &&
(*next)->ready((*next)->plugin) != 0) {
Void::Log::warn("Plugin.Manager",
"reload '{}' aborted: activation failed", name);
return std::unexpected{LoadError::ActivationFailed};
}
// Atomic swap. The old instance keeps living while any acquired
// handle still pins it; it is destroyed when the last one drops.
entry.current.store(std::move(*next), std::memory_order_release);
+10
View File
@@ -44,6 +44,11 @@ namespace
}
}
[[nodiscard]] bool ready() const noexcept
{
return config_ != "reject";
}
private:
std::string config_;
@@ -75,4 +80,9 @@ void void_plugin_configure(void* instance, const char* config)
{
static_cast<ConfigurablePlugin*>(instance)->apply_config(config);
}
int void_plugin_ready(void* instance)
{
return static_cast<ConfigurablePlugin*>(instance)->ready() ? 0 : -1;
}
}
+54
View File
@@ -110,3 +110,57 @@ Void::Testing::Test http_client_connection_refused_is_error()
const auto resp = client.get("http://127.0.0.1:1/");
Void::Testing::expect(!resp.has_value());
}
Void::Testing::Test http_client_timeout_bounds_a_stalled_server()
{
// A server that accepts and then never responds. Without an enforced
// Request::timeout the sync read blocks forever (Asio's sync emulation
// poll()s on would-block with no deadline).
struct StallServer {
int fd = -1;
std::uint16_t port = 0;
int conn = -1;
std::thread worker;
StallServer()
{
fd = ::socket(AF_INET, SOCK_STREAM, 0);
int yes = 1;
::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
sockaddr_in addr{};
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr.sin_port = 0;
::bind(fd, reinterpret_cast<sockaddr*>(&addr), sizeof(addr));
socklen_t len = sizeof(addr);
::getsockname(fd, reinterpret_cast<sockaddr*>(&addr), &len);
port = ntohs(addr.sin_port);
::listen(fd, 1);
worker = std::thread([this] {
conn = ::accept(fd, nullptr, nullptr);
// Never write a byte; hold the connection open.
});
}
~StallServer()
{
if (conn >= 0) ::close(conn);
if (worker.joinable()) worker.join();
if (fd >= 0) ::close(fd);
}
};
StallServer server;
Void::Net::HttpClient client;
Void::Net::Request req;
req.url = "http://127.0.0.1:" + std::to_string(server.port) + "/stall";
req.timeout = std::chrono::seconds{1};
const auto start = std::chrono::steady_clock::now();
const auto resp = client.send(req);
const auto elapsed = std::chrono::steady_clock::now() - start;
Void::Testing::expect(!resp.has_value());
// Well under the old "forever": the deadline tripped around 1s.
Void::Testing::expect(elapsed < std::chrono::seconds{5});
}
+25
View File
@@ -67,4 +67,29 @@ Void::Testing::Test configure_skipped_without_provider()
Void::Testing::expect_eq(configurable(h)->configure_calls(), 0);
}
Void::Testing::Test activation_failure_keeps_current_instance()
{
Void::FileSystem::TempDir tmp{"void_cfg_ready"};
const auto so = tmp.path() / "plugin.so";
std::filesystem::copy_file(VOID_CONFIGURABLE_PATH, so);
std::string payload{"accepted"};
PluginManager mgr{{.config_provider = [&payload](std::string_view) {
return payload;
}}};
Void::Testing::expect(mgr.load(so).has_value());
auto before = mgr.acquire("ConfigurablePlugin");
Void::Testing::expect_eq(configurable(before)->last_config(),
std::string_view{"accepted"});
payload = "reject";
const auto result = mgr.reload("ConfigurablePlugin");
Void::Testing::expect(!result.has_value());
Void::Testing::expect(result.error() == LoadError::ActivationFailed);
auto after = mgr.acquire("ConfigurablePlugin");
Void::Testing::expect(after.get() == before.get());
Void::Testing::expect_eq(configurable(after)->last_config(),
std::string_view{"accepted"});
}
#endif // configurable plugin available
+21 -8
View File
@@ -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
+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;