From 487f974f653e30b83bca16dd6fd88d242703df91 Mon Sep 17 00:00:00 2001 From: comavius Date: Sun, 6 Oct 2024 22:12:45 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20logic=20of=20time=20limit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- judge-control-app/src/remote_exec/ssh.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/judge-control-app/src/remote_exec/ssh.rs b/judge-control-app/src/remote_exec/ssh.rs index db25078..5c9b7ed 100644 --- a/judge-control-app/src/remote_exec/ssh.rs +++ b/judge-control-app/src/remote_exec/ssh.rs @@ -103,10 +103,15 @@ impl SshConnection { Ok(output) }; let timeout_future = async move { - let result = timeout(execution_time_limit, exec_future) + let start_time = tokio::time::Instant::now(); + let result = timeout(execution_time_limit + Duration::from_secs(1), exec_future) .await .map_err(|e| anyhow::Error::from(e)) .context("Execution time limit exceeded")?; + let elapsed = tokio::time::Instant::now().duration_since(start_time); + if elapsed >= execution_time_limit { + return Err(anyhow::anyhow!("Execution time limit exceeded")); + } result }; let result: Result = timeout_future