Skip to content

S07-21 - A VM's End in wb-proxyd

Purpose: How wb-hostd ends a VM’s hand-off sockets in the one wb-proxyd, and how the VM’s last event records reach its stop record without one VM’s stop or backlog taking the other VM’s network down.

Requirements: SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another., SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter., SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.

Tests: C02-streams-and-tlsC02-streams-and-tls: Streams, TLS, and the Inspection CAThe test cases for the streams wb-proxyd takes over: the hand-off from wb-netd, the first-byte and TLS checks, upstream addresses, the HTTP request form, and the inspection CA's leaves, rotation, and keys., C11-host-daemonsC11-host-daemons: Host Daemons, Audit, and DisksThe test cases for the host daemons' own checks: wb-vmd's device set and slots, the image build bundle, supervision, the accounting and event channels, the daemon log pipes, the audit writer, free space, and the data…

Brief: B754-handoff-contractB754-handoff-contract: What happens to one VM's hand-off socket, from its creation to its end?S04-12-descriptor-passing, S07-20-handoff-sockets and S07-21-vm-end settle the hand-off contract in one place.

HandoffSocketEnd names the VM, the generation, a socket number, and whether the VM stops. wb-proxyd closes every socket of the VM and generation whose number is at or below the one named, with every stream that came on them. It answers HandoffSocketEnded with the same four values, also when it holds none of those sockets.

There are two kinds, and wb-hostd sends each at most once:

  • A socket end doesn’t stop the VM. wb-hostd sends it for a socket that wasn’t final before one of these: it fails by a deadline, or its wb-netd exits or is ended. It names that socket. wb-proxyd runs step 1 of “Order at a VM stop” only, and its answer has the sequence 0. wb-hostd refuses any other value.
  • A stop end says the VM stops. wb-hostd sends it once for the generation when the VM stops, is saved, or its start is refused. It names the highest number wb-hostd offered for the generation, whatever each socket’s state. wb-proxyd runs every step.

wb-hostd keeps one wait for each end it sent, keyed by VM, generation, number and the stop flag, apart from the socket states of S07-20-handoff-socketsS07-20-handoff-sockets: Hand-off SocketsThe life of one VM's hand-off socket: its identity, the acknowledgments of both ends, how it closes, who a failure is charged to, what each restart does to it, and which of its decisions reach the audit log.. So a socket end and a stop end for the same number have their own waits. That covers these cases:

  • a socket fails, and then the VM stops;
  • a start’s socket fails, and the start is refused;
  • a wb-netd exits just before its VM’s stop end is sent.

When an end is sent, each socket it covers that isn’t final becomes ended. A socket already final keeps its state. A socket end is sent only for a socket that wasn’t final before, so a wb-netd that exits after the stop end causes none. HandoffSocketEnded is never stale. One that matches no wait is refused, as a crash of wb-proxyd (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves., “Control channels”).

wb-hostd sends the stop end before it stops the VM’s wb-netd (S04-09-netd-startS04-09-netd-start: Starting `wb-netd`How wb-hostd starts and stops each VM's wb-netd, what the program inherits, its profile, and what it does before its start message., “Stop”). A HandoffSocketClosed for peer-closed that the stop then causes names an ended socket, so it is stale and charges no one. wb-netd sees its socket close first, so an honest wb-netd records handoff-socket-ended at each stop. The stop record after it tells that apart from a failure. No socket of the generation follows its stop end: wb-hostd refuses one with vm-stopped.

wb-proxyd then, in this order:

  1. closes the VM’s sockets and streams up to the number, and cancels each of their handlers’ upstream dial, name lookup and secret fetch in progress;
  2. waits for every running handler of the VM and generation to queue its last event record, those of streams an earlier socket end closed included, at most a bound in code shorter than the answer’s deadline;
  3. counts each handler that didn’t in a run with the rule stream-end-unrecorded, and queues the counts of the VM’s open runs;
  4. answers HandoffSocketEnded with the sequence number of its last queued event record that names the VM and generation, or 0 when it sent none.

Step 2 can’t wait on a peer, because a close ends every write in progress (S07-20-handoff-socketsS07-20-handoff-sockets: Hand-off SocketsThe life of one VM's hand-off socket: its identity, the acknowledgments of both ends, how it closes, who a failure is charged to, what each restart does to it, and which of its decisions reach the audit log., “wb-proxyd’s end”). No step waits on the event channel’s delivery or on room in its queue. The records of a close go into the queue even at its cap, as S09-13-event-sendersS09-13-event-senders: Event SendersHow wb-hostd tells the senders of event records about the audit budgets, what it holds back, and when it stops a VM for its records. (“The hold”) bounds them. So an honest wb-proxyd answers within the deadline whether or not wb-hostd reads its channel.

After its stop answer, wb-proxyd queues no record that names the VM and generation, and it records nothing for an ended generation. A handler that finishes late drops its record, and the stream-end-unrecorded count stands for it. After wb-hostd sends the stop end, it sends wb-proxyd no PolicyChange or ActivePeriodStart for the VM, and no message that names the ended generation. The placeholder set, CaIssue and CaRemove name no generation, and CaSet and CaAccept name a newer one, so they stay allowed.

Each event record has a sequence number (S04-08-records-and-boundsS04-08-records-and-bounds: Records, Versions and BoundsThe records daemons send wb-hostd, the build version rules between processes, the bounds on host work a guest can cause, and logs., “Event records”). wb-hostd reads wb-proxyd’s channel up to the sequence the stop answer names, then ends the VM’s events (Hub.End). So the VM’s stop record has every count wb-proxyd sent, and no record of the VM comes after its end.

wb-hostd refuses a stop answer whose sequence is below the one of the last record that names the VM and generation it read from that wb-proxyd. A refused answer is a crash of wb-proxyd. A high sequence isn’t refused, because the read below ends at its own bound.

That read runs under the stop allowance of S09-13-event-sendersS09-13-event-senders: Event SendersHow wb-hostd tells the senders of event records about the audit budgets, what it holds back, and when it stops a VM for its records. (“At a VM’s stop”). It reads past the hold. Its bound is as many records as the allowance gives a wb-netd, plus the records the closes of every VM’s sockets may queue past the cap. So the read’s last sequence is the last one read when the answer came plus that bound. Records of another VM read under it count toward that VM’s budget as usual. The read ends at the first of:

  • the named sequence;
  • the read’s last sequence, logged with event-stop-allowance;
  • the end of wb-proxyd’s channel;
  • a deadline in code, which ends wb-proxyd with handoff-end-read-timeout. The exit counts toward its restart limit.

wb-hostd then ends the VM’s events. When the read stopped short, the stop record names the rule, the named sequence and the last one read, so a reader knows the records between them are missing.

wb-proxyd may name a VM and generation on its event channel from before the first HandoffSocket of that generation up to the sequence its stop answer names. wb-hostd opens the window before it sends that HandoffSocket.

A record that names a generation above its slot’s last ended generation that doesn’t run, as one whose window hasn’t opened, ends wb-proxyd with event-record-invalid.

A record that names a generation at or below its slot’s last ended generation is late: it comes after a read that stopped short, or above the named sequence. wb-hostd keeps only the last ended generation of each slot, so a lower generation that never ran is late too. So is a record of a VM whose stop wb-hostd decided for the margin (S09-13-event-sendersS09-13-event-senders: Event SendersHow wb-hostd tells the senders of event records about the audit budgets, what it holds back, and when it stops a VM for its records., “The margin”).

A late record doesn’t end wb-proxyd, because that would cost every other VM its network (T14-shared-proxydT14-shared-proxyd: One proxy process serves both VMsOne wb-proxyd serves the work VM and the isolated VM (S04-architecture, "Processes").). wb-hostd writes it as its own record, and logs it with event-vm-ended. Per end of the VM’s slot it writes at most the stop allowance of late records, and drops each one past that, logged with event-vm-ended. It writes the count of the drops as one audit record at the slot’s next end (S09-13-event-sendersS09-13-event-senders: Event SendersHow wb-hostd tells the senders of event records about the audit budgets, what it holds back, and when it stops a VM for its records., “Late records”).

A late record gets no budget notice and counts toward no margin. So a late record fails closed for its own VM only, and a high named sequence gives no open license to name a stopped VM.

The answer has the same deadline as an acknowledgment (egress.AckTimeout). It covers steps 1 to 3, which close sockets and streams and queue records. If it passes, wb-hostd ends wb-proxyd with handoff-end-timeout, and the exit counts toward its restart limit.

A wait ends with the wb-proxyd it was sent to. When wb-proxyd exits or is ended, every wait for an end it didn’t answer ends too. For a stop end, wb-hostd reads what is left on the channel under the allowance and ends the VM’s events. A new wb-proxyd never gets an end for a socket it wasn’t given: wb-hostd logs handoff-stop-end-skipped and sends none. While no wb-proxyd runs, a VM’s stop sends no end and ends the VM’s events at once.

When wb-proxyd exits or is ended with records unsent, those records are lost. wb-hostd writes one audit record for each VM it served, with the rule proxyd-records-lost, the exit’s rule, and the last sequence it read. A VM’s stop record names the same.

wb-proxyd decides the messages about one VM in order. It runs each VM’s end and each socket’s steps apart from its control loop. So a wait for one VM never delays a message about another VM.

wb-hostd keeps each wait on its own as well. After a wb-proxyd restart, each running VM’s new socket goes through its states alone. A wb-netd that withholds HandoffSocketHeld fails only its own VM’s socket.

A VM’s budget never holds wb-proxyd’s channel: a sender that ignores it has its own VM stopped (S09-13-event-sendersS09-13-event-senders: Event SendersHow wb-hostd tells the senders of event records about the audit budgets, what it holds back, and when it stops a VM for its records., “The margin”). Only a full audit queue holds the channel, and the end doesn’t depend on that hold. wb-proxyd queues the end’s records past its cap and answers without waiting on delivery, and wb-hostd reads past the hold under the allowance.

The end is its own exchange, before wb-netd stops

Section titled “The end is its own exchange, before wb-netd stops”

The end’s records may pass the queue’s cap

Section titled “The end’s records may pass the queue’s cap”

Status: Draft