Skip to content

Commit 7aa30ff

Browse files
committed
fix: scheduler crash
Signed-off-by: Anton Whalley <[email protected]>
1 parent 07a6d3d commit 7aa30ff

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/core-dump-handler/values.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ daemonset:
4141
suidDumpable: 2
4242
vendor: default
4343
# interval: 60000
44-
# schedule: "1/60 * * * * *"
45-
useINotify: true
44+
schedule: "1/1 * * * * *"
45+
# useINotify: false
4646
deployCrioConfig: false
4747
includeCrioExe: false
4848
# S3 access

core-dump-agent/src/main.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use std::process;
1818
use std::process::Command;
1919
use std::time::Duration;
2020
use thiserror::Error;
21-
use tokio::runtime::Handle;
2221
use tokio_cron_scheduler::{Job, JobScheduler};
2322

2423
#[allow(dead_code)]
@@ -59,7 +58,7 @@ async fn main() -> Result<(), anyhow::Error> {
5958

6059
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
6160
let host_dir = env::var("HOST_DIR").unwrap_or_else(|_| DEFAULT_BASE_DIR.to_string());
62-
let core_dir = env::var("CORE_DIR").unwrap_or_else(|_| DEFAULT_CORE_DIR.to_string());
61+
let core_dir_command = env::var("CORE_DIR").unwrap_or_else(|_| DEFAULT_CORE_DIR.to_string());
6362
let suid = env::var("SUID_DUMPABLE").unwrap_or_else(|_| DEFAULT_SUID_DUMPABLE.to_string());
6463
let deploy_crio_config = env::var("DEPLOY_CRIO_CONFIG")
6564
.unwrap_or_else(|_| "false".to_string())
@@ -94,9 +93,8 @@ async fn main() -> Result<(), anyhow::Error> {
9493
info!("Uploading {}", file);
9594
process_file(p, &bucket).await;
9695
} else {
97-
let core_store = core_dir.clone();
98-
info!("Uploading all content in {}", core_store);
99-
run_polling_agent(core_store.as_str()).await;
96+
info!("Uploading all content in {}", core_dir_command);
97+
run_polling_agent().await;
10098
}
10199
process::exit(0);
102100
}
@@ -119,7 +117,7 @@ async fn main() -> Result<(), anyhow::Error> {
119117
format!("{}/core_pattern.bak", host_location).as_str(),
120118
format!(
121119
"|{}/{} -c=%c -e=%e -p=%p -s=%s -t=%t -d={} -h=%h -E=%E",
122-
host_location, CDC_NAME, core_dir
120+
host_location, CDC_NAME, core_dir_command
123121
)
124122
.as_str(),
125123
)?;
@@ -135,8 +133,6 @@ async fn main() -> Result<(), anyhow::Error> {
135133
&suid,
136134
)?;
137135

138-
let core_location = core_dir.clone();
139-
140136
create_env_file(host_location)?;
141137
// Run polling agent on startup to clean up files.
142138

@@ -155,7 +151,7 @@ async fn main() -> Result<(), anyhow::Error> {
155151
std::thread::sleep(Duration::from_millis(1000));
156152
}
157153
} else {
158-
run_polling_agent(core_location.as_str()).await;
154+
run_polling_agent().await;
159155
}
160156

161157
if !interval.is_empty() && !schedule.is_empty() {
@@ -180,7 +176,6 @@ async fn main() -> Result<(), anyhow::Error> {
180176
}
181177
}
182178

183-
let notify_location = core_location.clone();
184179
if !schedule.is_empty() {
185180
info!("Schedule Initialising with: {}", schedule);
186181
let sched = match JobScheduler::new().await {
@@ -190,12 +185,11 @@ async fn main() -> Result<(), anyhow::Error> {
190185
panic!("Schedule Creation Failed with {}", e)
191186
}
192187
};
193-
let s_job = match Job::new(schedule.as_str(), move |_uuid, _l| {
194-
let handle = Handle::current();
195-
let core_str = core_location.clone();
196-
handle.spawn(async move {
197-
run_polling_agent(&core_str).await;
198-
});
188+
189+
let s_job = match Job::new_async(schedule.as_str(), move |_uuid, _l| {
190+
Box::pin(async move {
191+
run_polling_agent().await;
192+
})
199193
}) {
200194
Ok(v) => v,
201195
Err(e) => {
@@ -231,14 +225,14 @@ async fn main() -> Result<(), anyhow::Error> {
231225
}
232226
};
233227
info!("INotify Initialised...");
234-
match inotify.add_watch(&notify_location, WatchMask::CLOSE) {
228+
match inotify.add_watch(&core_dir_command, WatchMask::CLOSE) {
235229
Ok(_) => {}
236230
Err(e) => {
237231
error!("Add watch failed: {}", e);
238232
panic!("Add watch failed: {}", e)
239233
}
240234
};
241-
info!("INotify watching : {}", notify_location);
235+
info!("INotify watching : {}", core_dir_command);
242236
let mut buffer = [0; 4096];
243237
loop {
244238
let events = match inotify.read_events_blocking(&mut buffer) {
@@ -264,7 +258,7 @@ async fn main() -> Result<(), anyhow::Error> {
264258
Some(s) => {
265259
let file = format!(
266260
"{}/{}",
267-
notify_location,
261+
core_dir_command,
268262
s.to_str().unwrap_or_default()
269263
);
270264
let p = Path::new(&file);
@@ -389,7 +383,8 @@ fn get_bucket() -> Result<Bucket, anyhow::Error> {
389383
Ok(Bucket::new(&s3.bucket, s3.region, s3.credentials)?.with_path_style())
390384
}
391385

392-
async fn run_polling_agent(core_location: &str) {
386+
async fn run_polling_agent() {
387+
let core_location = env::var("CORE_DIR").unwrap_or_else(|_| DEFAULT_CORE_DIR.to_string());
393388
info!("Executing Agent with location : {}", core_location);
394389

395390
let bucket = match get_bucket() {

0 commit comments

Comments
 (0)