Skip to content

Commit 4c217b5

Browse files
retry sys_unknown failures (#670)
1 parent 0faf927 commit 4c217b5

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

ic-cdk-timers/src/lib.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
//! ic_cdk_timers::set_timer(Duration::from_secs(1), async { ic_cdk::println!("Hello from the future!") });
99
//! # }
1010
//! ```
11+
//!
12+
//! # Details
13+
//!
14+
//! Timers internally use a bounded-wait self-call for error handling purposes. This is not guaranteed to
15+
//! remain the case in the future, but means that if the system is under heavy load, timers may begin to
16+
//! slow down by a lot as the self-calls begin to time out and the timers are rescheduled for the next global
17+
//! timer tick. This also means that each executed timer incurs the cycle cost of a canister call.
1118
1219
#![warn(
1320
elided_lifetimes_in_paths,
@@ -234,13 +241,16 @@ unsafe extern "C" fn timer_scope_callback(env: usize) {
234241
let reject_code = ic0::msg_reject_code();
235242
match reject_code {
236243
0 => {} // success
237-
2 => {
238-
// Try to execute the timer again later.
239-
TIMERS.with_borrow_mut(|timers| timers.push(timer));
240-
if Rc::strong_count(&batch) == 1 {
241-
// last timer in the batch
242-
MOST_RECENT.set(None);
243-
update_ic0_timer();
244+
2 | 6 => {
245+
// Double check that it exists - in case of SYS_TRANSIENT it may have completed.
246+
if TASKS.with_borrow(|tasks| tasks.contains_key(task_id)) {
247+
// Try to execute the timer again later.
248+
TIMERS.with_borrow_mut(|timers| timers.push(timer));
249+
if Rc::strong_count(&batch) == 1 {
250+
// last timer in the batch
251+
MOST_RECENT.set(None);
252+
update_ic0_timer();
253+
}
244254
}
245255
return;
246256
}

0 commit comments

Comments
 (0)