Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [EXC-1831] Low Wasm memory hook will run once the canister's unfrozen if it was scheduled before freezing #3455

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dragoljub-duric
Copy link
Contributor

@dragoljub-duric dragoljub-duric commented Jan 15, 2025

Problem:
@mraszyk noticed here that property:
”If the canister gets frozen immediately after the function is scheduled for execution, the function will run once the canister's unfrozen if the canister's wasm memory remains above the threshold t.”
is missing.

Solution:
When execution of the hook is stopped because of the freezing canister, add the hook again to the task queue.

@github-actions github-actions bot added the fix label Jan 15, 2025
Comment on lines +83 to +96
//`OnLowWasmMemoryHook` is taken from task_queue (i.e. `OnLowWasmMemoryHookStatus` is `Executed`),
// but its was not executed due to the freezing of the canister. To ensure that the hook is executed
// when the canister is unfrozen we need to set `OnLowWasmMemoryHookStatus` to `Ready`. Because of
// the way `OnLowWasmMemoryHookStatus::update` is implemented we first need to remove it from the
// task_queue (which calls `OnLowWasmMemoryHookStatus::update(false)`) followed with `enqueue`
// (which calls `OnLowWasmMemoryHookStatus::update(true)`) to ensure desired behavior.
canister
.system_state
.task_queue
.remove(ic_replicated_state::ExecutionTask::OnLowWasmMemory);
canister
.system_state
.task_queue
.enqueue(ic_replicated_state::ExecutionTask::OnLowWasmMemory);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic may also be implemented directly on the TaskQueue, but it will require an additional method (let's say reenable_on_low_wasm_memory_hook), which will further diverge from the queue interface. So I opted for implementing it this way, but I do not have a strong opinion on this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I might miss the context. Wouldn't it be better if we just follow the GlobalTimer pattern, i.e. set/reset the 'low memory' hook in the same places?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think these two are related (though I do not have the whole context about the implementation of GlobalTimer), here I think we have an easier problem. We just have a task that is taken from the task_queue, and if it is not executed because of the freezing of the canister, we want it to be executed as soon as it is unfrozen. Because of the way hook status is implemented to be StateMachine to make status to be Ready, given that the current status is Executed we first need to make it NotSatisfied and then Ready.

@dragoljub-duric
Copy link
Contributor Author

An alternative approach was, that instead of always updating the hook status to Executed whenever task_queue::pop_front() is called and the hook status is Ready, we keep the hook status Ready after task_queue::pop_front() is called and only once its execution is finished we update the hook status to Executed. But in my opinion conceptually that will not be so nice, because TaskQueue::pop_front() will not be popping anything.

@dragoljub-duric dragoljub-duric marked this pull request as ready for review January 15, 2025 11:30
@dragoljub-duric dragoljub-duric requested a review from a team as a code owner January 15, 2025 11:30
@dragoljub-duric dragoljub-duric changed the title fix: EXC-1831 If canister gets frozen immediately after the hook is scheduled for execution, the hook will run once the canister's unfrozen fix: [EXC-1831] Low Wasm memory hook will run once the canister's unfrozen if it was scheduled before freezing Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants