refactor(plugin): share timeout helpers between process and process::v4

Delete the 5 copy-pasted timeout helpers in process/v4.rs (CALL_TIMEOUT_DEFAULT, call_timeout, request_timeout, execute_code_timeout, base_max_floor, request_kind) and reuse the canonical process.rs versions, now pub(crate). Prevents floor drift between v1 and v4 paths. Net: +3 / -59, no behavior change. Verified: cargo check -p ocs_plugin_api clean, cargo test -p ocs_plugin_api --lib --features host (92 passed).
This commit is contained in:
Karim Jerbi committed 2026-09-18 14:18:23 +01:00
1 parent b7de6a3287
commit 1bc20b9ecc
2 files changed
+3 -59

No files matched your search

+2 -2
View File
@@ -193,7 +193,7 @@ fn call_timeout() -> Duration {
/// Per-request-kind timeout floors. The user-configured default is raised to
/// these minima so that no request kind can be configured into an unsafe value.
fn request_timeout(kind: &'static str) -> Duration {
pub(crate) fn request_timeout(kind: &'static str) -> Duration {
base_max_floor(call_timeout(), kind)
}
@@ -228,7 +228,7 @@ fn base_max_floor(base: Duration, kind: &'static str) -> Duration {
base.max(floor)
}
fn request_kind(req: &HostRequest) -> &'static str {
pub(crate) fn request_kind(req: &HostRequest) -> &'static str {
match req {
HostRequest::GetManifest => "GetManifest",
HostRequest::GetRibbon => "GetRibbon",
+1 -57
View File
@@ -17,63 +17,7 @@ use crate::ipc::v4::server::{
default_notify_rate_limit, run_host_reader_thread, HostIncoming, RateLimiter, V4HostShared,
};
use crate::process::PluginError;
/// Default maximum time to wait for a plugin call to respond.
const CALL_TIMEOUT_DEFAULT: Duration = Duration::from_secs(30);
fn call_timeout() -> Duration {
std::env::var("OCS_PLUGIN_CALL_TIMEOUT_SECS")
.ok()
.and_then(|s| s.parse().ok())
.map(Duration::from_secs)
.unwrap_or(CALL_TIMEOUT_DEFAULT)
}
/// Per-request-kind timeout floors.
fn request_timeout(kind: &'static str) -> Duration {
base_max_floor(call_timeout(), kind)
}
fn execute_code_timeout() -> Duration {
const DEFAULT: Duration = Duration::from_secs(60);
std::env::var("OCS_PLUGIN_EXECUTE_TIMEOUT_SECS")
.ok()
.and_then(|s| s.parse().ok())
.map(Duration::from_secs)
.unwrap_or(DEFAULT)
.max(DEFAULT)
}
fn base_max_floor(base: Duration, kind: &'static str) -> Duration {
#[cfg(test)]
if let Some(secs) = std::env::var("OCS_PLUGIN_TEST_FLOOR_SECS")
.ok()
.and_then(|s| s.parse().ok())
{
return base.max(Duration::from_secs(secs));
}
let floor = match kind {
"GetManifest" | "GetRibbon" => Duration::from_secs(5),
"Dispatch" => Duration::from_secs(10),
"InteractiveEvent" | "GetPrompt" | "NeedsEntityPick" => Duration::from_secs(2),
"ExecuteCode" => execute_code_timeout(),
_ => Duration::from_secs(1),
};
base.max(floor)
}
fn request_kind(req: &HostRequest) -> &'static str {
match req {
HostRequest::GetManifest => "GetManifest",
HostRequest::GetRibbon => "GetRibbon",
HostRequest::Dispatch { .. } => "Dispatch",
HostRequest::InteractiveEvent { .. } => "InteractiveEvent",
HostRequest::GetPrompt { .. } => "GetPrompt",
HostRequest::NeedsEntityPick { .. } => "NeedsEntityPick",
HostRequest::ExecuteCode { .. } => "ExecuteCode",
HostRequest::Shutdown => "Shutdown",
}
}
use crate::process::{request_kind, request_timeout};
type DeferredRequest = (u64, Option<u64>, Box<PluginRequest>);