Record bounded session/channel close diagnostics on agent and gateway
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-17 12:57:09 +01:00
parent 932586ef33
commit 90689dafd1
2 changed files with 14 additions and 5 deletions
+11 -1
View File
@@ -2546,7 +2546,9 @@ fn service_run(stop: &'static AtomicBool) -> Result<()> {
continue;
}
let start = Instant::now();
let _ = agent.session(stop).await;
if let Err(error) = agent.session(stop).await {
record_session_error(&agent.config.state_directory, &error);
}
if start.elapsed() > Duration::from_secs(60) {
backoff = 1;
}
@@ -2611,6 +2613,14 @@ pub fn main() -> Result<()> {
rmm_agent_windows::service::dispatch(service_run)
}
/// Operator diagnostics only: the bounded error chain of the last session end
/// in the agent's own private state directory. Never authority or retry input.
fn record_session_error(state: &Path, error: &anyhow::Error) {
let mut text = format!("{error:#}");
text.truncate(1024);
let value = serde_json::json!({"schema_version":1,"observed_at_utc":Utc::now(),"error":text});
let _ = std::fs::write(state.join("session-last-error.json"), value.to_string());
}
#[cfg(test)]
mod tests {
use super::*;
+3 -4
View File
@@ -102,10 +102,9 @@ pub async fn connect(
.max_message_size(MAX_MESSAGE)
.max_frame_size(MAX_MESSAGE)
.on_upgrade(move |mut socket| async move {
if channel(&state, &mut socket, tenant, agent, expires)
.await
.is_err()
{
if let Err(error) = channel(&state, &mut socket, tenant, agent, expires).await {
// Operator diagnostics only: the bounded error chain, no payloads or keys.
eprintln!("WSS_CHANNEL_CLOSED agent={agent} error={error:#}");
let _ = socket.send(Message::Close(None)).await;
}
}))