Troubleshooting

On this page

Every refusal Hotcode makes names its reason. This guide lists them, what each means and what to do. Reasons appear in the output of mix hotcode.*, in {:error, reason} tuples from the API, and in the audit log.

First checks

mix hotcode.status TARGET --key alice.key
mix hotcode.deploy TARGET --key alice.key --dry-run

status shows the deployed version, history and accepting. --dry-run shows the plan and every analyzer finding without changing anything.

Authorization errors

reason meaning fix
{:not_configured, _} the node has no trusted_keys, allowed_prefixes or audience set all three (see Getting started)
{:insufficient_signatures, %{valid: n, required: m}} fewer than threshold distinct trusted keys signed have the missing signers run mix hotcode.sign; check each key is in trusted_keys
{:wrong_audience, name} the patch was built for another environment build against the right node, or fix audience
:expired the patch is older than its window (15 min) rebuild; use --ttl-minutes if review takes longer
:issued_in_the_future the signer's clock is more than a minute ahead fix the clock
{:replayed_or_stale, last_seq} the node already accepted this patch or a later one rebuild; a patch can only be applied once
:bad_statement, :malformed_envelope, {:bad_envelope, _} not a valid envelope rebuild with mix hotcode.build
:bundle_hash_mismatch the patch does not match what was signed someone modified the file; rebuild and re-sign
:version_mismatch the patch version differs from the signed version rebuild
:too_large the envelope or its contents exceed the size cap (max_envelope_bytes, default 64 MB) ship less in one patch
{:bad_envelope, {:bad_archive, reason}} the archive is not the format Hotcode.Archive reads: an extension header, a link, a bad name, more than 4096 entries (see Limits) rebuild with mix hotcode.build; do not repack envelopes with tar
:manifest_mismatch, {:bad_beam, name} the bundle's manifest does not list exactly its beams, or a beam is not an uncompressed beam file rebuild with mix hotcode.build
{:policy_denied, modules} the patch touches modules outside allowed_prefixes, or core/Hotcode modules allow the prefix, or do not patch those modules
{:base_mismatch, modules} the node runs different code than the patch was built against rebuild against the node as it is now (someone else deployed, or a node is out of step)
{:unbound_modules, modules} the signed base does not cover every module the patch touches rebuild with mix hotcode.build
:locked the kill switch is engaged Hotcode.unlock/0 once safe
{:locked_out, ms} too many rejected envelopes wait, or Hotcode.unlock/0
:unsigned_patch_rejected an unsigned bundle was handed to the loader (API use) sign it, or use the tasks
401 over HTTP, no detail deliberate: every authentication failure looks identical check the key is trusted, the URL, and that the request was made with --key

Analyzer findings

{:error, {:blocked, findings}} lists findings with severity :block. Each has a code:

code severity meaning what to do
:otp_mismatch block built with a different OTP than the node runs build with the node's OTP
:elixir_mismatch warn different Elixir minor version build with the node's Elixir
:build_env warn the patch was compiled in a Mix environment other than prod build with MIX_ENV=prod
:removed_exports warn a changed module no longer exports functions the loaded one does make sure no job queue, message in flight or capture still names them, or they fail with :undef
:protocol_impl_not_shipped warn an implementation of a protocol outside allowed_prefixes is left out of the patch (reported by mix hotcode.build) ship it with a release, see protocol implementations
:self_upgrade block the patch touches Hotcode itself upgrade Hotcode with a normal rolling deploy
:nif warn if the module is new, block if it replaces a loaded one a module contains a NIF a new one needs nothing (this is how a side-by-side NIF ships). Replacing one: in-place application restart (below), or a rolling restart
:on_load warn if new, block if replacing a module has @on_load same
:dependency_bump info, warn for a pre-release an application changes version by semver patch or minor informational
:major_bump block, warn if accepted a major bump, a 0.x minor bump, a downgrade or a non-semver version read the changelog, then --accept-major APP at build time, see dependency bumps
:application_callback block a module with the Application behaviour changed (any function of it, also when a library macro expands to use Application); start/2 will not run again keep that module to one-line delegations and change the modules it calls; otherwise same as above
:unloadable block a beam cannot be loaded on this node usually an OTP mismatch; rebuild
:no_rollback_binary block the beam on disk differs from the one loaded, so rollback could not be guaranteed deploy from a different build directory than the node runs from, or restart the node onto a known release
:supervisor warn a supervisor's child specs changed see restart-free replacement
:removed info a module will be unloaded informational
:closure_in_state warn, block with block_on_closure_in_state: true a process the deploy touches keeps a closure defined in a patched module; the finding carries process, processes (how many share it), path (state.callbacks.0) and closure_module change the code that stores it to &Mod.fun/n or {M, F, A} before the next deploy of closure_module: from then on calling it raises :badfun (at once if it was made before an earlier deploy)
:closure_scan_sampled info struct_scan: [max_processes: n] capped the states read for closures informational
:struct_scan_limit block a struct changes and more processes than struct_scan: [max_processes: n] would have their state read narrow with struct_scan: [only: [...]], raise the limit, or ship the struct change with a restart, see struct scan at scale
:cross_node_contract warn the app calls a function the patch removes or adds on other nodes (:erpc, :rpc, Node.spawn, :gen_rpc with literal module and function); the finding carries caller, function and change during a roll that call gets :undef: see Clusters

Blocks that need a restart can be lifted for a replaced :nif, :on_load and :application_callback if both the signers pass --restart-app APP at build time and the node's operator lists APP in allow_app_restart. See In-place application restart. A signed --force overrides any block, which is almost never what you want.

Deploy-time failures

reason meaning what to do
{:lingering_old_code, %{module => pids}} processes still run a displaced version of a module, so the old slot cannot be purged. A hard purge would kill them stop those processes. Typical cause: a plain spawn loop that never makes a remote call. (A fun stored in state or ETS does not keep old code alive: it breaks with :badfun once the old code is purged, at the next deploy)
{:migration_failed, %{...}} a process could not migrate. reverted, killed and code_restored say what was undone fix upgrade/2 or code_change/3; reproduce with the state of the failed process
{:migration_failed, %{reason: {:unsupported_transition, old, new}}} a module became use Hotcode.Versioned at vsn: 2 or higher while the running release was not versioned: nothing says which shape its state has. Refused before loading deploy it at vsn: 1 first (the running state is kept), then change the state in vsn: 2 (state migration)
{:load_failed, reasons} the VM refused to load the new beams usually an OTP mismatch or a corrupt beam
{:vetoed_by_hook, hook, reason} your before_deploy/1 said no resolve what the hook checks, retry
{:suspend_failed, pid, reason} a process did not respond to :sys.suspend in time. Nothing was changed the process is blocked inside a call; find out why, or deploy at a quieter moment. If a carriers entry matches processes that wait on the deploy itself, the deploy can never finish: Hotcode excludes its own endpoint's processes, but your own request-handling processes must not be carriers
{:app_restart_refused, app, reason} an in-place restart was not allowed or possible {:not_permitted, ..} the operator did not allow it; {:has_dependents, ..} another running app needs it; {:has_included_applications, ..}
{:app_restart_failed, app, reason} the new code could not start the app; the deploy was undone fix start/2
{:app_restart_failed, app, reason, :undo_incomplete, _} the undo could not finish; the node is locked follow the runbook
{:crashed, %{code_restored: bool}} an exception mid-deploy read the Logger output for the stacktrace; if code_restored: false the node is locked

Rollback failures

reason meaning what to do
:nothing_to_roll_back the node has no hot-deployed version nothing to do
{:rollback_target_mismatch, %{asked:, running:}} the signed rollback names a different version than the node runs someone deployed since; re-issue the rollback against the current version
{:rollback_unavailable, modules} the old binaries were not available when this deploy was made (it was forced) restart the node onto a known release
{:lingering_old_code, _} as above, found before any state was touched stop the lingering processes, retry

Fixes, in code

A process crashes right after a deploy with a KeyError on a field you added. Its state still has the old shape: Hotcode did not find it. Processes running code under allowed_prefixes are found by their state; code outside it (a library's process holding your struct) needs carriers:

config :hotcode,
  allowed_prefixes: ["MyApp", "MyAppWeb"],        # "MyApp" does NOT match "MyAppWeb"
  carriers: [Bandit.DelegatingHandler]

The connection supervisor died during a deploy (or under load). Connection processes restarted after a normal exit count against its restart intensity:

DynamicSupervisor.start_child(
  MyApp.Sessions,
  Supervisor.child_spec({MyApp.Session, socket}, restart: :temporary)
)

Callers crash for a few milliseconds when a process is swapped or restarted. Tolerate the gap:

def count(tries \\ 100) do
  GenServer.call(__MODULE__, :count)
catch
  :exit, _ when tries > 0 -> Process.sleep(10); count(tries - 1)
end

def record, do: GenServer.cast(__MODULE__, :record)    # fire and forget: a gap is harmless

:major_bump blocks a dependency update. Read the changelog, then say so, in the signed statement:

mix hotcode.deploy https://prod:4747 --key alice.key --accept-major jason

Common situations

Modules outside your prefix are "not shipped"

mix hotcode.build prints not shipped: N module(s) differ but are outside the node's allowed_prefixes. This usually means a dependency built in a different directory than the running release: rebar3 builds embed ?FILE, so the beams differ byte for byte though nothing changed. It is harmless: those modules are left out. If you do intend to patch a dependency, add its prefix to allowed_prefixes and build in the same path as the release.

If the modules listed are your own, a prefix is missing. "MyApp" does not match MyAppWeb, so a Phoenix application whose config says allowed_prefixes: ["MyApp"] ships no controller, LiveView or channel change. List every top-level namespace of your code: allowed_prefixes: ["MyApp", "MyAppWeb"] (and MyAppDatabase or the namespace of a path dependency you deploy).

"Nothing to deploy" although I changed code

The node already runs this build, or the only differences are outside allowed_prefixes (printed as not shipped). Check you built with the same MIX_ENV as the release.

The deploy is refused with :no_rollback_binary on a dev node

You deployed from the directory the node runs from. The mix compile that preceded the deploy overwrote the beams on disk, so the code on disk no longer equals what is loaded and a rollback could not restore the old code. Run the node from one directory and deploy from another (the examples/pulse project does this).

base_mismatch right after a successful deploy

You are deploying the same envelope twice, or deploying a patch built before someone else's deploy. Rebuild: the patch is only valid on top of the exact code it was built against.

A node did not pick up a deploy after restarting

Check that store_dir is set and writable, whether the node's audit.log shows persist_failed, and whether the stored patch still fits the release: a release that has moved past it discards the patch at boot (the log says no_longer_fits_this_release).

Connections dropped during a deploy

Hotcode itself does not close sockets. Check whether the process that owned the socket was one of the ones replaced (Hotcode.Swap, child spec change, application restart) and whether it was refused for handoff (see the lost list in the report and what can be handed off).