CredoHotUpgrades.Check.SupervisorInitSideEffects (CredoHotUpgrades v1.0.0)

Copy Markdown View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of high and works with any version of Elixir.

Explanation

The appup instruction a hot upgrade uses to update a supervisor, {update, Module, supervisor}, loads the new supervisor module and re-reads init/1 to get its new child specifications. Re-reading means running it, on the live supervisor process, the same call that ran when the node booted: supervisor:code_change/3 in OTP calls Module:init(Args) directly.

A side effect sitting in a supervisor's init/1, an ets:new/2 with a name already taken, a second :telemetry.attach, an Application.put_env/3, runs again and fails or duplicates work on that second call, even though nothing about the supervisor's own behaviour needed it to. Keep a supervisor's init/1 free of side effects, the same discipline Application.start/2 already asks for: a hot upgrade can call this one a second time on a node that never restarted.

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.