From b53c15e5c3232c102f6453645fbdd23d8e12ea5c Mon Sep 17 00:00:00 2001 From: JacobLinCool Date: Sat, 3 Jun 2023 13:36:27 +0800 Subject: [PATCH] fix: remote input error --- src/server/judge.rs | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/server/judge.rs b/src/server/judge.rs index fafab23..d977390 100644 --- a/src/server/judge.rs +++ b/src/server/judge.rs @@ -105,32 +105,31 @@ pub async fn run_specs(wasm: Box<[u8]>, specs: Vec) -> JudgeResults { let mut tasks = Vec::new(); for spec in specs { - let check = spec.check_spec().await; - if let Err(e) = check { - let task = task::spawn_local(async move { (Err(e), Err("".to_string()), None) }); - tasks.push(task); - continue; - } + let wasm = wasm.clone(); + let task = task::spawn(async move { + let check = spec.check_spec().await; + if let Err(e) = check { + return (Err(e), Err("".to_string()), None); + } - let input = spec.make_input().await; - if let Err(e) = input { - let task = task::spawn_local(async move { (Ok(spec), Err(e), None) }); - tasks.push(task); - continue; - } - let input = input.unwrap(); - let stdin = input.stdin.clone(); + let input = spec.make_input().await; + if let Err(e) = input { + return (Ok(spec), Err(e), None); + } + let input = input.unwrap(); + let stdin = input.stdin.clone(); - let (cost_limit, memory_limit) = spec.limits(); - let wasm = wasm.clone(); + let (cost_limit, memory_limit) = spec.limits(); - let task = task::spawn_blocking(move || { - info!("Running judge for spec: {:?}", spec); - let result = run::run(wasm, cost_limit, memory_limit, stdin); - info!("Judge finished for spec: {:?}", spec); - (Ok(spec), Ok(input), Some(result)) - }); + let task = task::spawn_blocking(move || { + info!("Running judge for spec: {:?}", spec); + let result = run::run(wasm, cost_limit, memory_limit, stdin); + info!("Judge finished for spec: {:?}", spec); + (Ok(spec), Ok(input), Some(result)) + }); + task.await.unwrap() + }); tasks.push(task); }