# FEATURE REQUEST: If pre\_upgrade fails, revert canister to earlier state snapshot of before pre\_upgrade ran and discard current pre\_upgrade logic

**URL:** <https://forum.dfinity.org/t/feature-request-if-pre-upgrade-fails-revert-canister-to-earlier-state-snapshot-of-before-pre-upgrade-ran-and-discard-current-pre-upgrade-logic/17605>\
**Category:** Rust\
**Created:** [December 22, 2022, 11:00am UTC](https://forum.dfinity.org/t/feature-request-if-pre-upgrade-fails-revert-canister-to-earlier-state-snapshot-of-before-pre-upgrade-ran-and-discard-current-pre-upgrade-logic/17605 "2022-12-22T11:00:43Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![roman-kashitsyn](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/roman-kashitsyn/32/3802_2.png) [@roman-kashitsyn](https://forum.dfinity.org/u/roman-kashitsyn)\
**Post date:** [December 23, 2022, 3:58pm UTC](https://forum.dfinity.org/t/feature-request-if-pre-upgrade-fails-revert-canister-to-earlier-state-snapshot-of-before-pre-upgrade-ran-and-discard-current-pre-upgrade-logic/17605/11 "2022-12-23T15:58:53Z")

</div>

> [@saikatdas0790](#):
>
> The `try_pre_upgrade` with a canister upgrade mode of only canister lifecycle changes is a naive solution that I came up with to handle this without making breaking changes to existing API. Probably has holes that I am unable to foresee.

I think I understand what you mean now.

You want the system to execute the following calls during an upgrade:

```auto
C1.pre_upgrade()
C2.post_upgrade()
C2.pre_upgrade()

```

So the system exercises the `pre_upgrade` hook at least once before accepting the new version.

Note that nothing stops you from calling the `pre_upgrade` hook from your `post_upgrade` hook. You don’t need a new system feature for that.

This scheme will save you from trivial errors in the `pre_upgrade` hooks but not errors caused by increased data size. If I understand correctly, the problem in your case was the following:

```auto
C1.pre_upgrade()
C2.post_upgrade()
... C2 functions normally
... Accumulating a lot of data and leaking memory
C2.pre_upgrade() <- traps

```

If it’s the case, then calling `pre_upgrade` right after `post_upgrade` would not have resolved your issue.

---

_[View the full topic](https://forum.dfinity.org/t/feature-request-if-pre-upgrade-fails-revert-canister-to-earlier-state-snapshot-of-before-pre-upgrade-ran-and-discard-current-pre-upgrade-logic/17605)._
