Skip to content

Commit 3631086

Browse files
committed
Implement timeout handling
Signed-off-by: Tim Buchwaldt <[email protected]>
1 parent 2386e91 commit 3631086

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

core-dump-composer/src/config.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub struct CoreParams {
3838
pub directory: String,
3939
pub hostname: String,
4040
pub pathname: String,
41+
pub timeout: u64,
4142
pub namespace: Option<String>,
4243
pub podname: Option<String>,
4344
pub uuid: Uuid,
@@ -56,6 +57,12 @@ impl CoreConfig {
5657
let directory = matches.value_of("directory").unwrap_or("").to_string();
5758
let hostname = matches.value_of("hostname").unwrap_or("").to_string();
5859
let pathname = matches.value_of("pathname").unwrap_or("").to_string();
60+
let timeout = matches
61+
.value_of("timeout")
62+
.unwrap_or("60")
63+
.parse::<u64>()
64+
.unwrap();
65+
5966
let uuid = Uuid::new_v4();
6067

6168
let params = CoreParams {
@@ -67,6 +74,7 @@ impl CoreConfig {
6774
directory,
6875
hostname,
6976
pathname,
77+
timeout,
7078
namespace: None,
7179
podname: None,
7280
uuid,
@@ -292,6 +300,14 @@ pub fn try_get_matches() -> clap::Result<ArgMatches> {
292300
.takes_value(true)
293301
.help("Hostname (same as nodename returned by uname(2))"),
294302
)
303+
.arg(
304+
Arg::new("timeout")
305+
.short('T')
306+
.long("timeout")
307+
.required(false)
308+
.takes_value(true)
309+
.help("Timeout in seconds to wait for processing of the Coredump"),
310+
)
295311
.arg(
296312
Arg::new("test-threads")
297313
.long("test-threads")

core-dump-composer/src/main.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,34 @@ use std::fs::File;
99
use std::io;
1010
use std::io::prelude::*;
1111
use std::process;
12+
use std::sync::mpsc::channel;
13+
use std::thread;
14+
use std::time::Duration;
1215
use zip::write::FileOptions;
1316
use zip::ZipWriter;
1417

1518
mod config;
1619
mod logging;
1720

1821
fn main() -> Result<(), anyhow::Error> {
19-
let mut cc = config::CoreConfig::new()?;
22+
let (send, recv) = channel();
23+
let cc = config::CoreConfig::new()?;
24+
let timeout = cc.params.timeout.clone();
25+
26+
thread::spawn(move || {
27+
let result = handle(cc);
28+
send.send(result).unwrap();
29+
});
30+
31+
let result = recv.recv_timeout(Duration::from_secs(timeout));
32+
33+
match result {
34+
Ok(inner_result) => inner_result,
35+
Err(error) => panic!("Timeout: {}", error),
36+
}
37+
}
38+
39+
fn handle(mut cc: config::CoreConfig) -> Result<(), anyhow::Error> {
2040
cc.set_namespace("default".to_string());
2141
let l_log_level = cc.log_level.clone();
2242
let log_path = logging::init_logger(l_log_level)?;

0 commit comments

Comments
 (0)