wasm_worker_sup (wasm v0.16.0)

View Source

Internal: supervises the reaper, so a worker needs nobody to start one.

The reaper is the node-wide process that cleans up after a request whose owner is gone. It is started one of two ways, both built by reaper_spec/0 so that the two can never disagree:

  • At boot, on configured roots. With scratch_roots set in the wasm application environment, the reaper starts with the application. That is when a crashed node's leftover directories are found and cleaned, which is why production should set it. A configured root belongs to one node at a time: a reaper treats a journal record from another node's incarnation as orphaned and deletes what it names.
  • On first use, on a root of its own. Without scratch_roots, the first wasm_script_worker:start_link/2,3 starts it with one root, scratch, in a directory under the user cache named for this node and OS process, so no two live nodes share it. The reaper removes that directory at a clean shutdown when nothing is left in it. After a crash of the whole node it is not reclaimed.

reaper_options in the application environment is passed to the reaper as its settings; a key it does not know refuses the start, naming the key.

suspend_reaper/0 and resume_reaper/0 exist for wasm_adapter_conformance, whose cases stop and restart a reaper of their own by hand.

Summary

Functions

Make sure a reaper is running, starting the supervised one if not.

The reaper's child spec: configured roots when scratch_roots is set, a generated root of this node's own otherwise. The only place either is built.

Undo suspend_reaper/0. With scratch_roots configured the reaper starts at once, so recovery on those roots does not wait for the next worker.

Stop the supervised reaper and start no other until resume_reaper/0.

Functions

ensure_reaper()

-spec ensure_reaper() -> ok | {error, term()}.

Make sure a reaper is running, starting the supervised one if not.

Does nothing when a reaper is already running, including one started by hand, when the reaper is suspended, or when the wasm application is not.

init/1

reaper_spec()

-spec reaper_spec() -> supervisor:child_spec().

The reaper's child spec: configured roots when scratch_roots is set, a generated root of this node's own otherwise. The only place either is built.

resume_reaper()

-spec resume_reaper() -> ok | {error, term()}.

Undo suspend_reaper/0. With scratch_roots configured the reaper starts at once, so recovery on those roots does not wait for the next worker.

start_link()

-spec start_link() -> supervisor:startlink_ret().

suspend_reaper()

-spec suspend_reaper() -> ok.

Stop the supervised reaper and start no other until resume_reaper/0.

For a test that runs a reaper of its own, by hand. The supervised one is shut down cleanly, so a root it generated is removed if it was idle.