From 289d61730c819c124d647199c7804b3ca4ca89fd Mon Sep 17 00:00:00 2001 From: "fupan.lfp" Date: Tue, 11 Feb 2020 10:02:44 +0800 Subject: [PATCH] grpc: fix the issue of crash agent when didn't find the process It's better to catch the error of couldn't find the process in tty_win_resize service, other wise, an invalid process id could crash the agent. Fixes: #137 Signed-off-by: fupan.lfp --- src/agent/src/grpc.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/agent/src/grpc.rs b/src/agent/src/grpc.rs index 1946005657..b6d3eeaacf 100644 --- a/src/agent/src/grpc.rs +++ b/src/agent/src/grpc.rs @@ -926,7 +926,19 @@ impl protocols::agent_grpc::AgentService for agentService { let eid = req.exec_id.clone(); let s = Arc::clone(&self.sandbox); let mut sandbox = s.lock().unwrap(); - let p = find_process(&mut sandbox, cid.as_str(), eid.as_str(), false).unwrap(); + let p = match find_process(&mut sandbox, cid.as_str(), eid.as_str(), false) { + Ok(v) => v, + Err(e) => { + let f = sink + .fail(RpcStatus::new( + RpcStatusCode::InvalidArgument, + Some(format!("invalid argument: {}", e)), + )) + .map_err(|_e| error!(sl!(), "invalid argument")); + ctx.spawn(f); + return; + } + }; if p.term_master.is_none() { let f = sink