louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
ADR 0060: OS signals, graceful shutdown, and supervised applications
Status: Proposed (2026-10-23, issue #306); needs engineering review (#44), in particular the signal thread's interplay with the scheduler (Signals).
Context
A Louise program could not learn that it was asked to stop: std/os and std/process had no signal API. toki2's stress test, in fedora-minimal:44 with podman, measured both consequences:
podman stop takes | Exit code | |
|---|---|---|
| no init | 10.3 s | 137 (SIGKILL after the grace period) |
--init | 0.2 s | 143 (killed by SIGTERM, no cleanup) |
- As PID 1, SIGTERM was ignored: Linux drops a signal sent to PID 1 when its disposition is the default.
- Otherwise it killed the program at once: in-flight requests were cut, nothing stopped accepting first, pooled connections were not closed.
Reading std/supervisor for a fix showed gaps too: the restart limit had no time window (toki2's 11th crash in weeks would take the server down), a supervisor could not be told to stop its children in order, every child was restarted the same way, and nesting supervisors was not tested.
Decision
Signals
- One thread takes them.
tl_mainandtl_main_programstart it before any other runtime thread (louise_rt/src/signals.rs):- They install a handler for SIGTERM, SIGINT and SIGHUP. It never runs; its only job is to make the kernel deliver the signals to PID 1.
- They block the three signals. Every later thread inherits the mask: the scheduler's threads, the blocking pools and the console writer. So no Louise code, C callback or blocking call is interrupted, and nothing is
EINTR'd. - The
louise-signalsthread takes them withsigwait.
- Delivery is a message.
os.signals([Term, Interrupt, Hangup]) -> Subject<Signal>registers the calling actor's new subject; several actors may subscribe.- The signal thread never touches the scheduler. It records the signal and wakes the reactor, as a finished blocking call does.
- A scheduler thread then sends it to every live subscriber, as a nullary
Signalconstructor (signals::collect). It does so between slices and when idle, so a busy scheduler delivers within a slice.
- Nobody subscribed (or every subscriber stopped) means the program ends as the default action would:
- the console is flushed first;
- the status is 128 + the signal's number: 143 for SIGTERM, 130 for SIGINT, 129 for SIGHUP;
- this holds as PID 1 too, so
podman stoptakes milliseconds without--init.
- Deadlock detection treats a live subscriber as something the outside can still wake. A program whose only actor waits for SIGTERM is waiting, not deadlocked.
- The interpreter accepts subscriptions and delivers nothing, as it runs blocking calls inline: signals need
--native. Ctrl-C keeps endinglouise runas before. - What is left to the default: other signals (SIGQUIT, SIGUSR1...) keep their dispositions. SIGPIPE is not touched either: TLS writes avoid it with
MSG_NOSIGNAL(ADR 0038).
process.stop and Shutdown
ExitReasongainsShutdown, added last so the runtime's constructor numbers hold:Normal0,Killed1,Crashed2,Shutdown3.process.stop(pid), a newprocoperation (the fifteenth,PROC_OPS), asks an actor to stop:- an actor that traps exits gets
ExitSignal(self(), Shutdown), to clean up and return; - any other stops at once with reason
Shutdown, which links propagate like any abnormal exit and monitors see.
- an actor that traps exits gets
- A root that stops with
Shutdownexits 0: it was asked to stop, and did. - This is OTP's
exit(Pid, shutdown).killstays the brutal kill.
Draining an HTTP server
http.serve_until(server, settings, handler, stop) serves like serve_with until any message arrives on stop, a subject of any message type that the caller owns. That can be os.signals([Term]) itself, process.exits() for a main that traps exits under [application], or a subject another actor sends on. Then:
- The acceptor gets a
Stopevent, and the listener is closed (net.close_listener, new):- the socket is shut down, so new clients are refused at once;
- an actor parked in
acceptis woken (Shared::wake_token), andacceptfails with "the listener is closed".
- The acceptor asks every open connection to close. This reuses ADR 0012 Revision 3's drain: idle connections close at once, busy ones after their current response, with
Connection: close. Connections accepted just before the stop are asked as their watchdogs report them. - It waits until they have ended, for
settings.drain_timeoutat most (new, default 10 s), then kills the connection actors still running. serve_untilreturns. A crash of the acceptor isserve_until's crash.
The accept loop is unchanged until a stop, so serving costs the same.
Supervisors
Spec(strategy, children, intensity, period_ms)andsupervisor.run(spec):- more than
intensityrestarts withinperiod_msmilliseconds make the supervisor give up; - giving up stops the other children first, then crashes;
- a negative
period_mscounts over the supervisor's life. supervise(strategy, children, max_restarts)stays as it was, a lifetime count, so it still needs noclock.
- more than
- Child kinds, as OTP's, via
ChildWith(name, start, restart, shutdown_timeout):Permanentis restarted after a crash and after it returns;Transientonly after a crash; a return or aShutdownmeans it is done;Temporaryis never restarted.Child(name, start)keeps its meaning: transient, which is what the supervisor did before, with 5 s to stop.
- Ordered shutdown. A supervisor told to stop (a
Shutdownexit signal from a non-child) stops its children last-started first:- each one gets
process.stop, then is killed if it is not done within itsshutdown_timeout; - the supervisor returns once they are all done.
- A supervisor child of another (
ChildWith(..., fn() { supervisor.run(...) }, ...)) stops its own children the same way, so a tree stops leaves first.
- each one gets
[application]: a supervised main
[application]
restart = "transient" # permanent | transient | temporary
intensity = 5 # at most 5 restarts...
period_ms = 60000 # ...within 60 s, else exit non-zero
shutdown_timeout_ms = 10000 # on a signal, main's time to stop
signals = ["term", "int"] # term | int | hup: start a shutdown
Programs keep a plain
main; the policy is deployment configuration, so it lives in the manifest. The section is the root package's; a dependency's is ignored. Without it, nothing changes:mainruns once, and the program exits when it returns or panics.With it,
louise runandlouise buildadd a generated module,+application, which no file can be named or import. Itsmainis the program's entry, and callssupervisor.application(Application(...), fn() { main.main() }). The package'smainmust therefore bepub. Both back ends get the same behaviour from plain Louise.supervisor.applicationtraps exits, subscribes to the listed signals, and runsmainlinked:mainreturns: the program exits 0, for every kind. Whetherpermanentshould runmainagain after a normal return is left open; it does not.maincrashes:temporaryends the program with that panic (status 101).transientandpermanentrestartmain, unless that is more thanintensityrestarts withinperiod_ms; then the program ends with the last panic, and systemd, podman or Kubernetes take over.- One of the signals arrives:
mainis stopped (process.stop). Amainthat traps exits getsShutdown, can drain (serve_until) and clean up, then returns. One that does not stops at once, with what it linked. Aftershutdown_timeout_msit is killed. The program then exits 0.
Boot is part of
main, so a restart re-runs it. That is fine when boot steps are idempotent:- settings are read again;
- migrations use
CREATE ... IF NOT EXISTS; - a crashed
main's listener is released, sohttp.listenbinds again.
The intensity bounds a crash loop at boot: a broken
DATABASE_URLgivesintensityquick restarts, then a non-zero exit with the panic printed.Tooling:
louise checkreports an invalid section, with its place in the manifest: unknown keys,intensityorperiod_msbelow 1, a negative timeout, an unknown kind or signal.louise testignores the section; tests have their own harness.Precedence: the manifest is the only source today. An operator override (
LOUISE_RESTART_INTENSITY, say) is left for when someone needs it. So islouise checkwarning aboutpermanentwith amainthat obviously returns: since a normal return always exits, it would warn about nothing.
Consequences
- Containers stop promptly:
podman stoptakes milliseconds as PID 1, with or without--init. With[application]orserve_until, in-flight requests finish first. - Breaking changes:
ExitReasonhas a fourth constructor, so amatchon it without a wildcard needs aShutdownarm (E0301 says so).Settingshas a ninth field,drain_timeout;Settings(..http.defaults(), ...)is unaffected.prochas a fifteenth operation. A handler ofprocwritten in Louise (none in the repository) needs astopclause.
- The process signal mask: blocking the three signals in every runtime thread means a C library that relies on receiving SIGINT or SIGTERM itself no longer does. No binding in the repository does. A child process started by C code inherits the mask and should reset it.
- A signal arriving once
mainhas returned, while the program writes its last output and exits, is not delivered: a live subscriber's message would have no scheduler to carry it. Without a subscriber, it ends the program at once, as before.
Verification
crates/louise/tests/signals.rs:- a subscriber gets SIGHUP and SIGTERM as messages, cleans up and exits 0;
- without one, SIGTERM, SIGINT and SIGHUP end the program in under a second with 143, 130 and 129;
- as PID 1 (a new PID namespace,
unshare -Urpf), SIGTERM still does.
http_drain.rs, on SIGTERM:- an idle kept-alive connection is closed;
- new clients are refused;
- a slow request completes with
Connection: close; serve_untilreturns, and the program exits 0 in well under a second;- a request past the 2 s drain timeout is cut at 2 s.
tests/run/supervisor_shutdown.lse, in both back ends (natively on 1, 4 and 22 threads, without leaks):stopon trapping and non-trapping actors;- more than 3 crashes within a second give up, while the same crashes spread over more than the window keep going;
- temporary and permanent children;
- a tree stopped last-started first, a nested supervisor's leaf first, and a stubborn child killed after its timeout.
application.rs:- a
maincrashing twice then returning runs three times and exits 0, natively and in the interpreter; - three crashes with
intensity = 2end the program with the last panic, 101; - SIGTERM to a
mainthat traps exits runs its cleanup and exits 0, as PID 1 too; - a
mainignoring the shutdown is killed after 300 ms and exits 0.
- a
Alternatives considered
- A signal handler that sends the message itself: a handler may call only async-signal-safe functions, and delivering a message takes locks and allocates. A self-pipe registered with the reactor would work, but it ties delivery to the reactor's loop.
sigwaiton a thread of its own is simpler and needs no async-signal-safety. mainreturning asupervisor.Spec: this was the issue's first idea, a new signature formain. The manifest keepsmainplain and puts deployment policy with deployment configuration (the issue's refinement).- Restarting
mainblindly, without a window: a boot error would loop forever. - A field for the drain timeout on
serve_untilinstead of inSettings: the other limits of a server are inSettings, and a record update keeps call sites short.