Dfx deploy --network=ic failure

Hello,
//Hello,
When I was updating the container code, I encountered some problems,

//run
dfx deploy --network=ic
//or
dfx canister --network=ic install --all --mode=install
//error
The Replica returned an error: code 5, message: "Canister moi4t-aqaaa-aaaaa-qbbra-cai trapped explicitly: An error happened during the call: 5: Canister mjj2h-niaaa-aaaaa-qbbrq-cai cannot be installed because the canister is not empty. Try installing with mode='reinstall' instead.

The data in this container is needed and cannot be cleared, so you cannot use reinstall to re-overwrite the installation, but I guarantee that the owner is correct,

Try to use

dfx canister --network=ic install --all --mode=upgrade

To try to upgrade the container,

The Replica returned an error: code 5, message: "Canister moi4t-aqaaa-aaaaa-qbbra-cai trapped explicitly: An error happened during the call: 5: Canister mjj2h-niaaa-aaaaa-qbbrq-cai exceeded its allowed memory allocation"

What should I do? There are too many users of this project at present, and reinstall cannot be used.

help me! ! ! !

You can try installing using the --memory-allocation flag, set to a higher value (the default is 8):

https://sdk.dfinity.org/docs/developers-guide/cli-reference/dfx-canister.html#_dfx_canister_install

The official document says that a maximum of 256TB is allowed, but when I try to call the command set to be greater than 8GB, cli reports an error:

//run 
dfx canister --network=ic install --all --memory-allocation=16GB --mode=upgrade
The Replica returned an error: code 5, message: "Canister moi4t-aqaaa-aaaaa-qbbra-cai trapped explicitly: An error happened during the call: 5: MemoryAllocation expected to be in the range [0..8589934592], got 16000000000"

To be fair, network=ic points to the sodium alpha network, and won’t be pointed to mercury until Genesis. Can’t say I’ve personally tried allocating a terabyte of space on mercury yet though

The Replica returned an error: code 1, message: “Canister zsrsb-paaaa-aaaab-abbva-cai with memory allocation 10MiB cannot be installed because the Subnet’s remaining memory capacity is 0MiB”

1 Like

Hey Avi,

I opened a bug report here. The upper limit certainly isn’t 256TB for Sodium or Mercury. We’ll find the actual limit and update the documentation. Thanks for pointing this out.

Can I have any other suggestions? Currently I need to push the code into the container, but the cli always prompts smart reinstall. I still need the container content data, so I can’t use reinstall.

Is there any good way

If you try deploy many times, it will be deployed.

:handshake:
Hello
Is there any other way to upgrade the container jar? At present, I need to try to upgrade the container to try to deploy the code. Debug my problem

I’m pretty sure mode=reinstall won’t wipe your state, but I also don’t want to recommend something that would hurt your app.

In your shoes, I’d try testing an upgrade on your local network.

Long-term I think there’s an some strategic way you could provision a new canister and migrate the data, but that’s really far outside my wheelhouse

Okay, I will try it on the local network, thanks

When I use reinstall in the local network, the data in the container is lost, so I can’t use reinstall, and the function of reinstall is still the same as stated in the official document Are consistent, the container will be reinitialized

Hi Avi,

I am almost certain that, contrary to what you were told above, --mode=reinstall does wipe the state - it essentially recycles the old canister id for new code, starting from clean state.

--mode=upgrade is probably what you want, provided your code is written to make use of stable storage.

I’m not sure how to help you with the allocation question, unfortunately, but perhaps some other engineer can help. Is it possible that your upgrade code is allocating too many resources and another version could be written to avoid that? I can’t even tell if this is Motoko or Rust code.

You can also selectively upgrade single canisters (perhaps only the code and interface of one has evolved) not just all of them, if that helps avoid the resource exhaustion.

2 Likes

Thank you for your help,

When I upgrade the interface container as you said

dfx canister --network=ic install --mode=upgrade icp_forms

cli error

The Replica returned an error: code 5, message: "Canister moi4t-aqaaa-aaaaa-qbbra-cai trapped explicitly: An error happened during the call: 5: Canister mjj2h-niaaa-aaaaa-qbbrq-cai exceeded its allowed memory allocation"

I am thinking, is it caused by too much data in my interface container?

But when I upgrade the front-end container,

  dfx canister --network=ic install --mode=upgrade www

Is successful

Installing code for canister www, with canister_id m4olk-maaaa-aaaaa-qbbsa-cai
Authorizing our identity (icpFarms) to the asset canister...
Uploading assets to asset canister...

The interface container in the project code uses MoToKo

At present, I see the error of --mode=upgrade, test whether the container on the Internet is hard-coded and only allows a fixed space to be allocated. If the application mechanism is allowed to expand the container according to the document, perhaps this problem of mine can be solved

That could be, but I’m little confused by the two canister ids in the error message. Is the code of the canister available to read anywhere?

//This is the interface container
mjj2h-niaaa-aaaaa-qbbrq-cai
//This is the front-end container
m4olk-maaaa-aaaaa-qbbsa-cai
//Front-end container --mode=upgrade is successful

The problem is the interface container

At present, the data in the interface container is too large and important to our project, so it cannot be discarded.

There’s still a third canister id there though, the one that traps: moi4t-aqaaa-aaaaa-qbbra-cai ?