Dfx deploy to IC error: The Replica returned an error: code 5, message: "Canister <id> trapped: stable memory out of bounds"

Hi all,

My first post, apologies if this has already been answered. I saw a couple of similar posts, but the solutions offered did not help.

Here’s the command and the output:

steve@MacBook-Pro-5 hello (master) $ dfx deploy hello --network ic --no-wallet
Deploying: hello
All canisters have already been created.
Building canisters...
Installing canisters...
Upgrading code for canister hello, with canister_id jhzj3-dqaaa-aaaag-aaa6a-cai
The Replica returned an error: code 5, message: "Canister jhzj3-dqaaa-aaaag-aaa6a-cai trapped: stable memory out of bounds"

The backstory is that I was following Kyle’s post here: Deploying Your First Canister (NNS dapp)

I have a canister with cycles:

steve@MacBook-Pro-5 hello (master) $ dfx canister --network ic --no-wallet status hello
Canister status call result for hello.
Status: Running
Controllers: mukio-ckxox-lztlx-vefkj-c3dlc-2sbpa-vwkov-rzk2k-72l5x-okm3t-eae sn3cz-jtkyo-ege6o-wxb6a-4at6z-yer32-ytlzz-4qati-fbv2u-nixdn-eae x4ydt-ddd3n-zbbcc-y7pyn-7gbqq-fddgp-45zxe-26krf-ypzgm-g5pn5-7qe
Memory allocation: 0
Compute allocation: 0
Freezing threshold: 2_592_000
Memory Size: Nat(1637076)
Balance: 1_890_498_161_591 Cycles
Module hash: 0xe0df779f65fe44893d8991bef0f9af442bff019b79ec756eface2b58beec236f

I had successfully deployed the static site to the canister, but I’m now in a new repo, and am trying to deploy hello world to the same canister (backend only).

Ever since I switched to the new repo I have been getting this error.

Is it possible to deploy a new app to an existing canister?

If not, is there a way to reclaim the cycles and add them to a different canister?

Not sure what best practice is here.

Any input would be most appreciated!

1 Like

you can, but you need to

  1. build first
  2. then reinstall it

dfx canister --network ic install --mode reinstall [canister name]

1 Like

Thanks, @bytesun

If I try that I get this:

steve@MacBook-Pro-5 hello (master) $ dfx canister --network ic install --mode reinstall hello
Creating a wallet canister on the ic network.
The replica returned an HTTP Error: Http Error: status 404 Not Found, content type "text/html", content: <html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.21.3</center>
</body>
</html>

And I think this is something to do with having created the canister via NNS (as per Kyle’s blog post linked above).

If I try to add --no-wallet to the command, I get this:

steve@MacBook-Pro-5 hello (master) $ dfx canister --network ic install --no-wallet --mode reinstall hello
error: Found argument '--no-wallet' which wasn't expected, or isn't valid in this context

If you tried to supply `--no-wallet` as a PATTERN use `-- --no-wallet`

USAGE:
    dfx canister install [FLAGS] [OPTIONS] [canister]

For more information try --help

I should maybe start again with another canister that was not created via NNS?

try this

dfx canister --network ic --no-wallet install --mode reinstall hello

3 Likes

Awesome. Thanks a bunch, @bytesun

steve@MacBook-Pro-5 hello (master) $ dfx canister --network ic --no-wallet install --mode reinstall hello
Warning!
You are about to reinstall the hello canister.
This will OVERWRITE all the data and code in the canister.

YOU WILL LOSE ALL DATA IN THE CANISTER.

Do you want to proceed? yes/No
yes
Reinstalling code for canister hello, with canister_id jhzj3-dqaaa-aaaag-aaa6a-cai
1 Like

Got the same problem (stable memory out of bounds), solved with :

dfx canister uninstall-code --network ic --all

dfx deploy --network ic

The problem propably occured when I tried to deploy the same project with a different identity. The process has frozen during deployment

Just ran into this error locally.

In case anyone else runs into it, running dfx start --clean fixes the issue.

2 Likes