Skip to content

Commit fc087d6

Browse files
committed
Add timeout in acquire_r_main()
1 parent aafd634 commit fc087d6

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

crates/ark/src/r_task.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,19 @@ impl RTaskMain {
110110

111111
// Be defensive for the case an auxiliary thread runs a task before R is initialized
112112
fn acquire_r_main() -> &'static mut RMain {
113+
let now = std::time::SystemTime::now();
114+
113115
unsafe {
114116
loop {
115117
if !R_MAIN.is_none() {
116118
return R_MAIN.as_mut().unwrap();
117119
}
118120
std::thread::sleep(Duration::from_millis(100));
121+
122+
let elapsed = now.elapsed().unwrap().as_secs();
123+
if elapsed > 50 {
124+
panic!("Can't acquire main thread");
125+
}
119126
}
120127
}
121128
}

0 commit comments

Comments
 (0)