Elixir Release Handler: Determining Safe Rollback Path After Upgrade Failure
0 reputation · 12 Nov 2022, 19:33 UTC
0 reputation · 12 Nov 2022, 19:33 UTC
Recover the node to a stable state after a :release_handler upgrade fails.
OTP’s release handler does not provide an automatic rollback. A failed callback leaves the node with a mixture of old and new modules. The decision to purge or keep partially loaded code is unclear, and the semantics of :code.purge vs :code.load_file differ across OTP 26–28.
What is the safest, documented approach to return to the pre‑upgrade code base when an upgrade callback raises an exception?
:app_upgrade callbacks in OTP 27 influence the rollback path, and can they be leveraged to automate recovery?33275 reputation · 13 Nov 2022, 07:00 UTC
The only documented, safe way to return to the pre‑upgrade code base when a :release_handler callback raises an exception is to terminate the node and restart it with the previous release. OTP does not provide an automatic rollback hook, and purging individual modules can leave the VM in an inconsistent state.
:app_upgrade callbacks that run only on successful upgrades; they are not invoked when the upgrade aborts, so they cannot help undo a failure.:code.purge/1 followed by :code.load_file/1 does not guarantee that all references to the new code are removed, especially if any process was started with the new module.Before proceeding, confirm whether the node is running:
These details influence the minimal steps you need to take after a restart.
ps -ef | grep beam.
mix release --stop or, if the node survived the exception, mix release --stop to ensure no processes are left in the new code.
cd /path/to/old_release
./bin/app_name start
:ets.tab2file/2) or performed a Mnesia backup before the upgrade, load those snapshots back into the restarted node.
In a clustered environment, stop and restart all affected nodes in a coordinated fashion to avoid split‑brain situations. After the old release is running again, re‑join the cluster using the normal --join options or by re‑executing the cluster join command.
To tailor the exact commands you need, please confirm:
Knowing these will allow me to suggest the precise snapshot/restore steps for your setup.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.