Motoko Canister Upgrade Error

Hi guys,
I’m currently facing an issue while trying to upgrade one of my canisters (kitchen) and I keep running into this error:

Error: Failed while trying to deploy canisters. Caused by: Failed while trying to deploy canisters. Failed while trying to install all canisters. Failed to install wasm module to canister 'kitchen'. Failed during wasm installation call: The replica returned a replica error: reject code CanisterError, reject message Error from Canister 6cxww-biaaa-aaaal-adebq-cai: Canister called ic0.trap with message: 'canister_pre_upgrade attempted with outstanding message callbacks (try stopping the canister before upgrade)' Canister Backtrace: unknown function at index 40 . Consider gracefully handling failures from this canister or altering the canister to handle exceptions. See documentation: https://internetcomputer.org/docs/current/references/execution-errors#trapped-explicitly, error code None

Things I’ve Tried

  • Reinstalling the code with dfx canister install kitchen --mode upgrade
  • Confirmed pre_upgrade() is synchronous (no await or async behavior)

I use dfx version 0.16.0

For some weird reasons, it works sometimes if retried persistently.

Would appreciate any insights or guidance on this — especially from anyone who has encountered this

Does your canister make calls to other canisters that it needs to await?

Motoko will refuse to upgrade if your canister is waiting on a response from another canister (including itself).

Try doing dfx canister stop kitchen before you do attempt the upgrade.

This should allow the canister to refuse new requests while waiting for old requests to finish processing.

Once it is in a stopped state, it should have no outstanding message callbacks and can be upgraded.

1 Like

Thanks for the insight and so sorry for replying this late. I think the dfx cansiter stop kitchen does the job.