Skip to content

Commit

Permalink
fix(Judger): 🐛 cgroup_id should not be reused
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Jun 9, 2024
1 parent f6a4c91 commit bb24211
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 25 deletions.
1 change: 0 additions & 1 deletion judger/src/sandbox/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ pub enum Error {
#[error("io error")]
IoError(#[from] std::io::Error),
}
pub type Result<T> = std::result::Result<T, Error>;
11 changes: 5 additions & 6 deletions judger/src/sandbox/monitor/mem_cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ use crate::async_loop;

use super::{stat::*, *};
use cgroups_rs::{cgroup_builder::CgroupBuilder, Cgroup};
use std::{
sync::{atomic::Ordering, Arc},
vec,
};
use std::sync::{atomic::Ordering, Arc};
use tokio::{select, time::*};

/// maximum allow time deviation for cpu monitor
pub const MONITOR_ACCURACY: Duration = Duration::from_millis(80);

const CG_PATH_COUNTER: AtomicUsize = AtomicUsize::new(0);
lazy_static::lazy_static! {
pub static ref CG_PATH_COUNTER: AtomicUsize=AtomicUsize::new(0);
}

async fn monitor(cgroup: Arc<Cgroup>, cpu: Cpu) -> MonitorKind {
let wrapper = wrapper::CgroupWrapper::new(&cgroup);
Expand Down Expand Up @@ -135,7 +134,7 @@ impl super::Monitor for Monitor {
/// it is only guaranteed to below limitation provided + [`MONITOR_ACCURACY`].
async fn stat(self) -> Self::Resource {
// FIXME: check running process, this line is commented out because of uncollected process
// uncollected process is at state of not running, but pid is still in use
// uncollected process is at state of not running, but pid is still in use
// debug_assert!(self.cgroup.tasks().is_empty());
let wrapper = wrapper::CgroupWrapper::new(&self.cgroup);
(wrapper.memory(), wrapper.cpu())
Expand Down
3 changes: 0 additions & 3 deletions judger/src/sandbox/monitor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ impl<P: AsyncRead + Unpin> Monitor for StatMonitor<P> {
}

impl<P: AsyncRead + Unpin> StatMonitor<P> {
pub fn new() -> StatMonitorBuilder<P> {
StatMonitorBuilder::default()
}
pub fn get_cg_path(&self) -> &str {
self.mem_cpu.get_cg_path()
}
Expand Down
2 changes: 1 addition & 1 deletion judger/src/sandbox/monitor/stat.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
ops::{Add, AddAssign, Div, Mul},
ops::{AddAssign, Div, Mul},
time::Duration,
};

Expand Down
2 changes: 1 addition & 1 deletion judger/src/sandbox/monitor/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::async_loop;
use super::{hier::*, stat::*};
use cgroups_rs::{cpu::CpuController, cpuacct::CpuAcctController, memory::MemController, Cgroup};
use std::{ops::Deref, pin::pin};
use tokio::{sync::oneshot, task::JoinHandle, time};
use tokio::task::JoinHandle;

pub struct OOMSignal {
rx: Option<JoinHandle<()>>,
Expand Down
14 changes: 1 addition & 13 deletions judger/src/sandbox/process/process.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use super::{corpse::Corpse, error::Error, monitor::*, nsjail::*, Context, Filesystem};
use std::{
ffi::{OsStr, OsString},
os::unix::ffi::OsStrExt,
path::{Path, PathBuf},
path::PathBuf,
process::Stdio,
};
use tokio::{
Expand Down Expand Up @@ -77,17 +76,6 @@ pub struct Process<C: Context> {
stdout: DuplexStream,
}

fn get_inner_args<'a>(
mut args: impl Iterator<Item = &'a OsStr>,
mut root: OsString,
) -> Vec<OsString> {
// check spec before unwrap
root.push(args.next().unwrap());
let mut r = vec![root];
r.extend(args.map(|x| x.to_os_string()));
r
}

impl<C: Context> Process<C> {
pub fn new(context: C) -> Result<Self, Error> {
MonitoredProcess::new(context).map(Into::into)
Expand Down

0 comments on commit bb24211

Please sign in to comment.