# How does a timer task that is already running behave if the number of cycles required by the value of the 'freezing threshold' falls below the remaining amount?

**URL:** <https://forum.dfinity.org/t/how-does-a-timer-task-that-is-already-running-behave-if-the-number-of-cycles-required-by-the-value-of-the-freezing-threshold-falls-below-the-remaining-amount/31782>\
**Category:** Developers\
**Created:** [June 11, 2024, 7:54am UTC](https://forum.dfinity.org/t/how-does-a-timer-task-that-is-already-running-behave-if-the-number-of-cycles-required-by-the-value-of-the-freezing-threshold-falls-below-the-remaining-amount/31782 "2024-06-11T07:54:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![megared](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/megared/32/11028_2.png) [@megared](https://forum.dfinity.org/u/megared)\
**Post date:** [June 11, 2024, 7:54am UTC](https://forum.dfinity.org/t/how-does-a-timer-task-that-is-already-running-behave-if-the-number-of-cycles-required-by-the-value-of-the-freezing-threshold-falls-below-the-remaining-amount/31782/1 "2024-06-11T07:54:27Z")

</div>

The documentation says “stop new processing” as follows, but what exactly does this mean with regard to the timer task?

> **[1.6 Managing canisters | Internet Computer](https://internetcomputer.org/docs/current/tutorials/developer-journey/level-1/1.6-managing-canisters#setting-the-canisters-freezing-threshold)**
>
> Overview

> **[Topping up a canister | Internet Computer](https://internetcomputer.org/docs/current/developer-docs/smart-contracts/topping-up/topping-up-canister#managing-cycle-depletion-with-freezing-threshold)**
>
> Overview

> The freezing threshold is important because if a canister runs out of cycles, it will be uninstalled. The freezing threshold protects it from deletion, since if the cycles balance dips below the threshold, the canister will stop processing any new requests; however, it will continue to reply to existing requests.

I would like to know the specific behaviour in this regard.  
I understand that the Timer task reserves a task on the ic side and calls canister from the ic side.  
if the canister side is below freezing threthold, where is the error?

There is also a related contribution below, which is also of concern in this regard.

> [@What happens when a canister hits freezing threshold I will not do anything for a long time?](https://forum.dfinity.org/t/what-happens-when-a-canister-hits-freezing-threshold-i-will-not-do-anything-for-a-long-time/15790):
>
> What happens when a canister hits freezing threshold I will not do anything for a long time? I mean will not do anything for long time - lets say a year. Cycles will drop to zero, state (memory) will be lost and then…? Will the canister be removed entirely from IC? Will the controller of this canister be able to install the code and reuse the same canisterId? Or that canisterId will become available for all community (to create completely new canister)? Could not find answers in docs. Refe…

> Cycles will drop to zero, state (memory) will be lost and then…?

In terms of the moment below the threshold, the memory information is maintained, right?

---

<div class="post-metadata">

**Author:** ![berestovskyy](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/berestovskyy/32/3989_2.png) [@berestovskyy](https://forum.dfinity.org/u/berestovskyy)\
**Post date:** [June 11, 2024, 12:28pm UTC](https://forum.dfinity.org/t/how-does-a-timer-task-that-is-already-running-behave-if-the-number-of-cycles-required-by-the-value-of-the-freezing-threshold-falls-below-the-remaining-amount/31782/2 "2024-06-11T12:28:06Z")

</div>

hey negated,  
Regarding the timers, the [spec](https://internetcomputer.org/docs/current/references/ic-interface-spec#call-context-creation) reads:

> If canister `C` exports a method with name `canister_global_timer` , the global timer of canister `C` is set, and the current time for canister `C` has passed the value of the global timer, the IC will create the corresponding call context and deactivate the global timer.

Now, answering your question:

> the Timer task reserves a task on the ic side and calls canister from the ic side. if the canister side is below freezing threthold, where is the error?

If the canister is below the freezing threshold, the timer won’t be scheduled, but will remain active. The global timer will be scheduled and deactivated as soon as there are enough cycles.

Regarding the freezing threshold, the [spec](https://internetcomputer.org/docs/current/references/ic-interface-spec#ic-create_canister) reads:

> A canister is considered frozen whenever the IC estimates that the canister would be depleted of cycles before `freezing_threshold` seconds pass, given the canister’s current size and the IC’s current cost for storage.

> Calls to a frozen canister will be rejected with `SYS_TRANSIENT` reject code. Additionally, a canister cannot perform calls if that would, due the cost of the call and transferred cycles, would push the balance into frozen territory; these calls fail with `ic0.call_perform` returning a non-zero error code.

> Default value: 2592000 (approximately 30 days).

Now, answering your question:

> In terms of the moment below the threshold, the memory information is maintained, right?

The canister will be slowly draining the cycles balance below the freezing threshold to keep its memories and Wasm module for ~30 days.

After ~30 days, once the canister balance becomes zero, the canister will be uninstalled as described in the [spec](https://internetcomputer.org/docs/current/references/ic-interface-spec#canister-out-of-cycles).

Once the frozen canister balance is above the freezing threshold, the canister is back to normal.

---

<div class="post-metadata">

**Author:** ![megared](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/megared/32/11028_2.png) [@megared](https://forum.dfinity.org/u/megared)\
**Post date:** [June 12, 2024, 2:24am UTC](https://forum.dfinity.org/t/how-does-a-timer-task-that-is-already-running-behave-if-the-number-of-cycles-required-by-the-value-of-the-freezing-threshold-falls-below-the-remaining-amount/31782/3 "2024-06-12T02:24:12Z")

</div>

Thank you for even sharing the reference document.

> [@berestovskyy](#):
>
> If the canister is below the freezing threshold, the timer won’t be scheduled, but will remain active. The global timer will be scheduled and deactivated as soon as there are enough cycles.

This is also the case if a recurring task has been set up, as in the following enum, this means that if you have set up a recurring task like the following enum, scheduling and periodic execution will resume once the cycles have been replenished, is this correct? (meaning that the developer does not need to set up the task again).

> <https://github.com/dfinity/cdk-rs/blob/7fa27b03d0d891b30a89b1b281ca3ba0661f2750/src/ic-cdk-timers/src/lib.rs#L45-L48>

---

<div class="post-metadata">

**Author:** ![berestovskyy](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/berestovskyy/32/3989_2.png) [@berestovskyy](https://forum.dfinity.org/u/berestovskyy)\
**Post date:** [June 12, 2024, 8:27am UTC](https://forum.dfinity.org/t/how-does-a-timer-task-that-is-already-running-behave-if-the-number-of-cycles-required-by-the-value-of-the-freezing-threshold-falls-below-the-remaining-amount/31782/4 "2024-06-12T08:27:38Z")

</div>

There are two cases:

1. The canister balance is below the freezing threshold. In this case, the CDK code will be called only when the canister balance is above the freezing threshold as described above.

2. The canister balance is very close to the freezing threshold. In this case the Rust CDK code might be executed, but there might be not enough cycles to execute the user code. This was [fixed recently](https://forum.dfinity.org/t/changing-some-error-codes/28171/13), so the Rust CDK library should now retry user code execution once there are enough cycles.

So, to best of our knowledge, the periodic execution should gracefully handle low cycles balances in Rust CDK.

Note, there are likely still some corner cases, such as when the canister runs out of memory. In this case the Rust CDK code will panic, and the error message should be available in the canister log.

For completeness, all the timers are deactivated after a canister upgrade.

---

<div class="post-metadata">

**Author:** ![megared](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/megared/32/11028_2.png) [@megared](https://forum.dfinity.org/u/megared)\
**Post date:** [June 18, 2024, 8:25am UTC](https://forum.dfinity.org/t/how-does-a-timer-task-that-is-already-running-behave-if-the-number-of-cycles-required-by-the-value-of-the-freezing-threshold-falls-below-the-remaining-amount/31782/5 "2024-06-18T08:25:35Z")

</div>

> [@berestovskyy](#):
>
> So, to best of our knowledge, the periodic execution should gracefully handle low cycles balances in Rust CDK.

Thank you. I understood that it is handled gracefully, except for edge cases.
