mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-07-24 07:30:33 +00:00
feat: dynamic mesh idle_timeout from patch.cfg without container restart
When mesh.idle_timeout is present in patch.cfg, apply_patch_config() now updates all active peer sessions via a new p2p::update_idle_timeout() function and also updates the cached metric_thresholds array for future connections. Previously mesh.idle_timeout was only read at startup (p2p::init()) and could not be changed on a running node without a container restart. This is critical for operators who need to increase roundtime beyond mesh.idle_timeout * 4 — without this fix, increasing roundtime past 480000ms (at default idle_timeout of 120000ms) causes peer disconnections and permanent consensus failure. Implementation: - comm_server.hpp: added for_each_session() template to iterate live sessions - p2p.cpp: added update_idle_timeout() which updates metric_thresholds[4] and calls set_threshold(IDLE_CONNECTION_TIMEOUT) on all active sessions - conf.cpp: reads mesh.idle_timeout from patch.cfg in apply_patch_config(), calls p2p::update_idle_timeout() when value changes Sibling PRs (part of dynamic config series): - fix/dynamic-log-level-from-patch-cfg (already raised) - feat/dynamic-user-idle-timeout-from-patch-cfg (to be raised) Fixes: mesh connections dropping during long roundtimes
This commit is contained in:
@@ -322,6 +322,17 @@ namespace comm
|
||||
|
||||
message_processor_thread.join();
|
||||
}
|
||||
/**
|
||||
* Iterate over all active sessions and apply a function to each.
|
||||
* Used to update live session thresholds (e.g. idle_timeout) without restart.
|
||||
*/
|
||||
template<typename F>
|
||||
void for_each_session(F&& func)
|
||||
{
|
||||
std::scoped_lock<std::mutex> lock(sessions_mutex);
|
||||
for (T &session : sessions)
|
||||
func(session);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace comm
|
||||
|
||||
18
src/conf.cpp
18
src/conf.cpp
@@ -7,6 +7,9 @@
|
||||
#include "ledger/ledger_mount.hpp"
|
||||
#include "sc/contract_mount.hpp"
|
||||
|
||||
// Forward declaration to avoid circular dependency with p2p/p2p.hpp
|
||||
namespace p2p { void update_idle_timeout(const uint32_t timeout_ms); }
|
||||
|
||||
namespace conf
|
||||
{
|
||||
|
||||
@@ -876,6 +879,21 @@ namespace conf
|
||||
} catch (const std::exception &e) {
|
||||
LOG_ERROR << "Error applying log level from patch config: " << e.what();
|
||||
}
|
||||
// Apply mesh idle timeout change dynamically if present in patch config.
|
||||
// Updates all active peer sessions and future connections without restart.
|
||||
try {
|
||||
if (jdoc.contains("mesh") && jdoc["mesh"].contains("idle_timeout")) {
|
||||
const uint32_t new_idle_timeout = jdoc["mesh"]["idle_timeout"].as<uint32_t>();
|
||||
if (new_idle_timeout != cfg.mesh.idle_timeout) {
|
||||
cfg.mesh.idle_timeout = new_idle_timeout;
|
||||
temp_cfg.mesh.idle_timeout = new_idle_timeout;
|
||||
p2p::update_idle_timeout(new_idle_timeout);
|
||||
LOG_INFO << "Mesh idle timeout updated dynamically to: " << new_idle_timeout << "ms";
|
||||
}
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
LOG_ERROR << "Error applying mesh idle timeout from patch config: " << e.what();
|
||||
}
|
||||
LOG_INFO << "Contract config updated from patch file.";
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -70,6 +70,24 @@ namespace p2p
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update mesh idle timeout on all active peer sessions and for future connections.
|
||||
* Called from conf::apply_patch_config() when mesh.idle_timeout changes in patch.cfg.
|
||||
* Updates both the cached metric_thresholds array (for new sessions) and all
|
||||
* existing live sessions via set_threshold() so no restart is required.
|
||||
*/
|
||||
void update_idle_timeout(const uint32_t timeout_ms)
|
||||
{
|
||||
metric_thresholds[4] = timeout_ms;
|
||||
if (ctx.server.has_value())
|
||||
{
|
||||
ctx.server->for_each_session([timeout_ms](peer_comm_session &session) {
|
||||
session.set_threshold(comm::SESSION_THRESHOLDS::IDLE_CONNECTION_TIMEOUT, timeout_ms, 60000);
|
||||
});
|
||||
LOG_INFO << "Mesh idle timeout updated dynamically to: " << timeout_ms << "ms";
|
||||
}
|
||||
}
|
||||
|
||||
int start_peer_connections()
|
||||
{
|
||||
const uint16_t listen_port = conf::cfg.mesh.listen ? conf::cfg.mesh.port : 0;
|
||||
|
||||
Reference in New Issue
Block a user