fix(runtime-rs): add exited state to ensure cleanup

Set process status to exited at end of io wait, which indicate process
exited only, but stop process has not been finished. Otherwise, the
cleanup_container will be skipped.

Fixes: #6393

Signed-off-by: Yipeng Yin <yinyipeng@bytedance.com>
This commit is contained in:
Yipeng Yin 2023-03-02 15:46:05 +08:00
parent 65fa19fe92
commit 8030e469b2
4 changed files with 16 additions and 12 deletions

View File

@ -184,6 +184,7 @@ pub enum ProcessStatus {
Stopped = 3, Stopped = 3,
Paused = 4, Paused = 4,
Pausing = 5, Pausing = 5,
Exited = 6,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@ -56,6 +56,7 @@ impl From<ProcessStatus> for api::Status {
ProcessStatus::Stopped => api::Status::STOPPED, ProcessStatus::Stopped => api::Status::STOPPED,
ProcessStatus::Paused => api::Status::PAUSED, ProcessStatus::Paused => api::Status::PAUSED,
ProcessStatus::Pausing => api::Status::PAUSING, ProcessStatus::Pausing => api::Status::PAUSING,
ProcessStatus::Exited => api::Status::STOPPED,
} }
} }
} }

View File

@ -200,20 +200,22 @@ impl ContainerInner {
return Ok(()); return Ok(());
} }
self.check_state(vec![ProcessStatus::Running]) self.check_state(vec![ProcessStatus::Running, ProcessStatus::Exited])
.await .await
.context("check state")?; .context("check state")?;
// if use force mode to stop container, stop always successful if state == ProcessStatus::Running {
// send kill signal to container // if use force mode to stop container, stop always successful
// ignore the error of sending signal, since the process would // send kill signal to container
// have been killed and exited yet. // ignore the error of sending signal, since the process would
self.signal_process(process, Signal::SIGKILL as u32, false) // have been killed and exited yet.
.await self.signal_process(process, Signal::SIGKILL as u32, false)
.map_err(|e| { .await
warn!(logger, "failed to signal kill. {:?}", e); .map_err(|e| {
}) warn!(logger, "failed to signal kill. {:?}", e);
.ok(); })
.ok();
}
match process.process_type { match process.process_type {
ProcessType::Container => self ProcessType::Container => self

View File

@ -182,7 +182,7 @@ impl Process {
drop(exit_status); drop(exit_status);
let mut status = status.write().await; let mut status = status.write().await;
*status = ProcessStatus::Stopped; *status = ProcessStatus::Exited;
drop(status); drop(status);
drop(exit_notifier); drop(exit_notifier);