Problems with deleting a canister

when i try to delete a (stopped) canister, i get the result below.

How do i delete a canister and retrieve the cycles?

dfx canister delete Bazar_backend --ic
Please enter the passphrase for your identity: [hidden]
Decryption complete.
Beginning withdrawal of cycles; on failure try --no-wallet --no-withdrawal.
Setting the controller to identity principal.
Installing temporary wallet in canister Bazar_backend to enable transfer of cycles.
Attempting to transfer 2969289990002 cycles to canister zwmuh-ziaaa-aaaan-qelaa-cai.
Error: Failed to delete canister 'Bazar_backend'.
Caused by: Failed to delete canister 'Bazar_backend'.
  Failed to deposit 2969289990002 cycles into zwmuh-ziaaa-aaaan-qelaa-cai.
    Failed to call update function 'deposit_cycles' regarding canister 'zwmuh-ziaaa-aaaan-qelaa-cai'.
      Update call using wallet failed.
        The replica returned a replica error: reject code CanisterError, reject message Error from Canister ez4fu-xiaaa-aaaan-qmbra-cai: Canister ez4fu-xiaaa-aaaan-qmbra-cai is out of cycles, error code None

when i check the staus, the canister has started again and about 0.005T cycles are gone

dfx canister status --all --ic
Please enter the passphrase for your identity: [hidden]
Decryption complete.
Canister status call result for Bazar_backend.
Status: Running
Controllers: j6c6e-4p2az-veznb-gbwom-w3rma-54dcj-ol4lz-3hcex-b2xxw-y5sok-lae
Memory allocation: 0
Compute allocation: 0
Freezing threshold: 0
Memory Size: Nat(3677184)
Balance: 2_979_892_571_787 Cycles
Reserved: 0 Cycles
Reserved Cycles Limit: 5_000_000_000_000 Cycles
Module hash: 0xc1290ad65e6c9f840928637ed7672b688216a9c1e919eacbacc22af8c904a5e3
Number of queries: 0
Instructions spent in queries: 0

What dfx version are you using? Have you upgraded to version 0.20.0?

Yes, i upgraded to 0.20.0

Thank you for the confirmation. We will check and get back to you.

That’s a problem with dfx. Sorry about that. I know how to solve it but haven’t gotten around to fixing it yet.

Workaround for the meantime:
Call dfx canister --wallet <canister to delete> deposit-cycles --ic $(dfx identity --ic get-wallet) <cycles amount>. This will use the wallet that was installed in the canister you want to delete to send cycles to your actual cycles wallet. Given that you have 2.9T cycles in your canister you probably can use 2.8T or 2.7T in place of <cycles amount.
After withdrawing cycles manually you should be able to delete the canister with the --no-withdrawal flag, which will not try to withdraw cycles

2 Likes

Does that also include withdrawing frozen threshold?

Yes. dfx sets the freezing threshold to 0 before attempting to withdraw, so any previously reserved cycles are free to withdraw

1 Like