Limits
On this page
What Hotcode cannot do, what it does not detect, and where the implementation stops. The short list is in Features and support. The pitfalls to design around, with code, are in How it works.
Needs a restart
- OTP or Elixir upgrades.
- Changes to Hotcode itself.
- Replacing a loaded NIF or
@on_loadmodule, and any change to a module with theApplicationbehaviour (blocked as:application_callback, whichever function changed: the behaviour is read per module; a library macro that expands touse Applicationcounts), unless the application may be restarted in place (never a core application, or one that others depend on). See In-place application restart. A new NIF module needs no restart (NIFs). - No patch changes an application's
.appfile:Application.spec(app, :modules)and:application.get_key(app, :modules)keep the boot-time list, without the modules a patch added. Replacing the list through the application controller (the call release upgrades make,change_application_dataof:application_controller) also rewrites the application's environment from the.appfile andsys.config, dropping values set at runtime, so Hotcode does not do it.Hotcode.Loader.modules/1gives the list with hot-added modules, and theafter_deploy/1report listsnewandremovedmodules (see Hooks). - A dependency bump cannot change an application's
.appfile orpriv/. The node keeps reporting the version it booted with (Hotcode tracks the deployed one), and a rolling restart brings it onto the newmix.lock. See Dependency bumps. - Your own application's
priv/is never shipped either: a patch carries.beamfiles only. Static assets (priv/static, digested bundles andcache_manifest.json), templates or data files read at runtime (:code.priv_dir/1,Application.app_dir/2), gettext.pofiles andpriv/repo/migrationschange on a node only with a release. Route a change that touchespriv/orassets/to the normal release pipeline. Templates compiled into a module (HEEx,EEx.function_from_file/3) are code and are shipped. For assets that change more often than the code, serve them from outside the release, from a CDN or object storage, or from a directory set at runtime (Plug.Static, from: "/srv/my_app/static") that your own deploy step writes, and keep in mind that a hot patch referencing a new asset must not land before the asset does.
Database migrations
A hot deploy runs no Ecto migration: release_command, bin/my_app eval "MyApp.Release.migrate()"
and Kubernetes or Fly release jobs run when an image is deployed, not when a patch is. And since a
patch does not carry priv/repo/migrations, a node running the old release does not even have a
new migration file.
Use expand and contract, so that the code running at every moment works with the schema:
- Expand, before the patch. Add what the new code needs (a nullable column or one with a
default, a new table, a new index) and run it while the old code still serves. Either ship the
migration in a normal release, or run
mix ecto.migratefrom the same checkout the patch is built from (CI with database credentials), before the push. - Deploy the code hot. The patch reads and writes the new column. A rollback puts back code
that ignores it, so the expanded schema must stay valid for the old code too: no renames, no
NOT NULLwithout a default. - Contract, later. Drop the old column in a release once no running code, and no version a rollback could return to, reads it.
A before_deploy/1 hook is the wrong place to migrate: it runs the hook module the node already
has (the patch is not loaded yet), on every node of a roll, and it cannot see migration files the
release does not contain. Use it to veto, for example while a long backfill is still running.
Where it does not fit
- Nothing to keep across a restart: a stateless node with no long-lived connections and no costly state restarts faster than a patch is built and signed.
- Machines that stop and start on the image (scale to zero, serverless, an ephemeral disk
without
store_dir): a restarted machine runs the image, not the patch. - Desktop apps and packed runtimes (Burrito, Tauri sidecars), CLIs, escripts and libraries.
Hotcode pushes a patch built against the code a node runs; there is no documented flow for
a client that pulls patches, nor for patches that apply to several base builds
(
Hotcode.Loader.deploy_binary/2loads a signed envelope, but fetching, choosing and verifying the base is left to you).
Not detected
- Funs stored in ETS,
persistent_term, messages, timers, or in the state of a process the deploy does not touch, that point at replaced code fail withbadfunafter the second deploy that replaces their module. Hotcode keeps one displaced version until the next deploy. In the states of the processes a deploy does touch (their module changes, or they hold a changed struct), the plan finds them and reports:closure_in_state; the walk of one state stops after 24 levels or 20 000 terms, and whenstruct_scan: [max_processes: n]caps the number of states read. - Plain ETS tables are not migrated. A
Hotcode.Tableis (see state migration). - A plain
spawnloop never leaves the code it started on. - The assigns of a Phoenix channel or LiveView beyond its structs, unless its module has a
code_change/3(see state migration), and the assigns of a LiveComponent. - Messages between nodes must be compatible across two versions during a roll. A message format
change takes three releases (see Clusters). The plan reports remote calls to a
function the patch removes or adds only when the module and function are literal atoms
(
:cross_node_contract); not MFAs in variables, config or job args, and not message shapes.
Implementation limits
- Only
gen_server,gen_statemand supervisors started withproc_libare migrated.AgentandTaskare skipped on purpose. - A struct change reads the state of every process under
allowed_prefixes(16 at a time) to find its holders. On a node with tens of thousands of such processes, or with saturated schedulers, that and the suspension take seconds to minutes: numbers and settings in Operations. - Rollback needs the old binary, which the VM does not keep. If Hotcode cannot prove that the binary it has is what is loaded, the deploy is blocked.
- An in-place application restart keeps statically supervised
gen_*workers with safe state. Plain processes,AgentandTaskchildren, listening sockets and:sslconnections are lost and reported. Between the newstart/2and the restore, a restarted worker runs on the state its owninit/1built, so a call answered in that moment sees fresh state (what to do about it). - If the old code cannot be put back after a failed migration, the processes not yet migrated are killed so their supervisors restart them. Many kills in one supervisor can exceed its restart intensity.
- Keep
allow_app_restartempty until you have tried an in-place restart against your real application tree. It is the one mechanism that interrupts running code. It has been tested with purpose-built applications (examples/pulserestarts one inside a live Phoenix node), never by restarting Bandit or Phoenix themselves.
Archive format
Envelopes (.hcp) and bundles are gzip-compressed ustar archives, read by Hotcode.Archive
before any signature is checked. What it accepts:
- at most 64 MB per envelope (
config :hotcode, max_envelope_bytes:), 128 MB once inflated; - regular files only: no pax or GNU extension headers, links or directories;
- at most 4096 entries, each name at most 255 bytes, made of
A-Z a-z 0-9 . _ - + @ /, no absolute path, no.or..component, no name twice. So a module whose beam file name (Elixir.MyApp.Name.beam) is longer than 100 bytes needs a name of at most 95 bytes afterebin/, and module names with other characters cannot travel in a patch ({:cannot_pack, _}frommix hotcode.build); - beams uncompressed (
FOR1); a gzip-compressed beam is refused.
A beam's Attr chunk is hashed without creating atoms: up to 1 MB it is decoded with :safe;
when it names an atom the node does not have yet, or is larger, its top-level list is split
without decoding (same digest for a chunk the compiler wrote); a compressed term or a shape the
reader does not know is hashed as raw bytes. A shadow (the checks run before loading) is not made
for a beam whose literal table inflates past 16 MB: its checks run after loading instead.
What has been demonstrated, and how
examples/pulse demonstrates the features together on three nodes (Phoenix Channels, Postgres, a
Rust NIF, a dependency bump, hooks, supervision changes, a swap, an in-place application restart,
rolls, convergence, the deadman rollback and a node restart, watched by an external checker). It
is not part of mix test. What it does not show is listed in
the examples README.
LiveView and Bandit WebSocket handlers were demonstrated by an earlier example that is now only in the git history. The test suite covers each mechanism on its own (see How it is tested).