diff --git a/src/command/common.rs b/src/command/common.rs index e6e516f..b34023c 100644 --- a/src/command/common.rs +++ b/src/command/common.rs @@ -43,8 +43,13 @@ pub fn terminate_student_program(exec: &mut SyncExecutionContext) -> CommandResu for _ in 0..20 { std::thread::sleep(Duration::from_millis(100)); // Sensible amount? - let con = exec.lock().unwrap(); + let mut con = exec.lock().unwrap(); if con.thread_handle.as_ref().unwrap().is_finished() { + con.thread_handle + .take() + .unwrap() + .join() + .or(Err(CommandError::NonRecoverable("Supervisor thread panicked".into())))?; return Ok(()); } } diff --git a/src/command/execute_program.rs b/src/command/execute_program.rs index 46dcdcb..127d3ec 100644 --- a/src/command/execute_program.rs +++ b/src/command/execute_program.rs @@ -34,10 +34,7 @@ pub fn execute_program( // WATCHDOG THREAD let mut wd_context = exec.clone(); let wd_handle = std::thread::spawn(move || { - let exit_code = match supervise_process(student_process, timeout, &mut wd_context) { - Ok(code) => code, - Err(()) => 255, - }; + let exit_code = supervise_process(student_process, timeout, &mut wd_context).unwrap_or(255); log::info!("Program {}:{} finished with {}", program_id, timestamp, exit_code); let sid = ProgramStatus { program_id, timestamp, exit_code }; diff --git a/src/command/execution_context.rs b/src/command/execution_context.rs index c4d1301..0e234fc 100644 --- a/src/command/execution_context.rs +++ b/src/command/execution_context.rs @@ -46,7 +46,7 @@ impl ExecutionContext { } pub fn is_student_program_running(&self) -> bool { - self.running_flag + self.thread_handle.is_some() } pub fn has_data_ready(&self) -> bool {