| @@ -154,7 +154,7 @@ The decision above holds; these points refine it. |
| 154 | 154 | - Before its hello, a connection may send at most 1 KiB and must finish within `node_down_after_ms`. Connections without a hello are capped per source (*After the reviews*), so an unauthenticated host cannot lock nodes out. |
| 155 | 155 | - Each turn reads and writes a connection for at most 5 ms per direction, so a flooding peer cannot starve the others' heartbeats. |
| 156 | 156 | - Back-pressure: messages and spawn requests past `max_queue` bytes per peer park their sender (*Flow control*, below); other signals are not capped. |
| 157 | | −- **Full-mesh discovery is opt-in** (`[cluster] discovery = "mesh"`, `LOUISE_DISCOVERY`; #417). Each node sends signal op `03`, a list of peers: its advertised address and every up node whose address it got from its operator or from that node. Lists go only between nodes whose hellos both set flag bit 0: to a new peer at once, and to every peer at most once per heartbeat after a node comes up or goes down. Unknown names are dialed, at most `max_peers` of them. Addresses are hints: TLS checks the dialed name, a node's own entry or a dial that came up confirms its address, a third party's list replaces only an unconfirmed one, and a seed's never changes. A discovered node is redialed while some peer lists it, then forgotten after 10 × `node_down_after_ms`; seeds and `dist.connect` nodes are never forgotten. The advertised address is `LOUISE_ADVERTISE`, else the listen address when it is not unspecified (with the real port for port 0), else none. Without mesh, only seeds and `connect`ed nodes are redialed. |
| 157 | +- **Full-mesh discovery is opt-in** (`[cluster] discovery = "mesh"`, `LOUISE_DISCOVERY`; #417). Each node sends signal op `03`, a list of peers: its advertised address and every up node whose address it got from its operator or from that node. Lists go only between nodes whose hellos both set flag bit 0: to a new peer at once, and to every peer after a node comes up or goes down, at most once per heartbeat for each 256 peers up. Every peer gets the same list, encoded once and shared (it may hold the receiver's own entry, which the receiver ignores), and at most one unsent list waits per peer, replaced by newer ones. Unknown names are dialed, at most `max_peers` of them; a list longer than the receiver's `max_peers` is cut, not dropped. Addresses are hints: TLS checks the dialed name, a node's own entry or a dial that came up confirms its address, and a seed's never changes. Until a discovered node confirms its address, its dials go to its current listers' addresses in turn, by lister in connection order, so a lister's lie costs one failed dial per turn and cannot hold the others' out. A failed dial to an address only lists gave is logged through a throttle and kept out of `failures`. A discovered node is redialed while some peer lists it, then forgotten after 10 × `node_down_after_ms`; seeds and `dist.connect` nodes are never forgotten. The advertised address is `LOUISE_ADVERTISE`, else the listen address when it is not unspecified (with the real port for port 0), else none. Without mesh, only seeds and `connect`ed nodes are redialed. |
| 158 | 158 | - The scheduler's idler now returns once the program has finished. Before this, a thread that started idling after the last actor's nudge waited forever while the transport kept the program alive. |
| 159 | 159 | |
| 160 | 160 | **`std/dist`.** |
| @@ -191,7 +191,7 @@ The decision above holds; these points refine it. |
| 191 | 191 | - `spawn_on` to this node's own name encodes and decodes the argument, as a peer's request does. A mismatch between an entry's runtime and compiled hashes makes `start` return `Invalid`. |
| 192 | 192 | - `DistError` gains `UnknownEntry` and `Refused`; `WrongType` also covers an entry of another argument type. `dist.Remote<a>` aliases `std/dist/remote.Remote<a>`. |
| 193 | 193 | - Spawn requests are signals on the ordered stream, but they count against the queue cap, so `spawn_on` parks while the peer's queue is full. A spawner that dies with requests queued leaves their askers to time out. **`spawn_link_on`** (#415) is op `22`, with op `20`'s layout (a new op, since the request's decoder checks a fixed length). For a remote asker the spawner makes the actor unscheduled, then its link half and the `10` link frame under its lock, then schedules it, then queues the `21` answer; so the link reaches the asker's node ahead of the actor's messages, its exit and the answer. An asker gone by then answers `noproc` and the actor dies of it; an asker's node that is down means `noconnection`. A local asker gets `spawn_link`'s semantics, the orphan kill included. A timed-out asker stays linked to an actor whose pid it never learned. Op `22` gives a peer no new power: it could already spawn an entry and link to it. A node built before #415 drops op `22` as an unknown signal and the asker times out; stage 1 assumes one build per cluster, and the schema hash does not cover the runtime's ops. |
| 194 | | −- **A remote link's half and its frame are made under the linking actor's lock** (#415). Before, a kill from another thread between the two let the exit pass the link frame, and the peer stayed linked to a gone pid until the node was lost. Lock order: an actor's lock may be held while taking the node table's read lock and the transport's route queue; nothing takes an actor's lock under either. |
| 194 | +- **A remote link's half, its listing in `Dist` and its frame are made under the linking actor's lock** (#415), for `link` and for `spawn_link_on`. Before, a kill from another thread between the half and the frame let the exit pass the link frame, and the peer stayed linked to a gone pid until the node was lost; and a node lost after the frame was queued but before the actor was listed left the link with no `noconnection`. Lock order: an actor's lock, then the `Dist` ties' mutex (a leaf), or the node table's read lock, the `PROGRAM` read lock and the transport's route queue; nothing takes an actor's lock under any of them. |
| 195 | 195 | |
| 196 | 196 | **Flow control and `peers`.** |
| 197 | 197 | - **A sender to a full queue parks**, without blocking its scheduler thread, through `dist::send_parking`, as `std/net` parks on I/O: it registers a waiter, then retries, so a drain in between is not lost. The transport wakes a peer's parked senders when it takes that peer's whole queue (the low-water mark is an empty queue). A parked actor sends nothing else, so per-sender order holds. A sender that exits while parked, or whose peer is lost, has its message dropped and counted. |
| @@ -201,12 +201,12 @@ The decision above holds; these points refine it. |
| 201 | 201 | - `dist.peers ()` lists the nodes this node knows (every node up, every seed or `connect`ed node, and the `max_peers` most recently seen others: a new name forgets the least recently seen, #416), with its state (`Up`, or `Down(why)`), incarnation, round-trip time, queued bytes, and cumulative counts: sent, received, unsent, parked, dropped. |
| 202 | 202 | - `[cluster]` is the policy: `LOUISE_CLUSTER` may repeat its name but not change it, and `start` refuses another cluster's `Config`; `LOUISE_LISTEN` overrides its `listen`. `max_frame` is `max_message_bytes` plus the kind byte and the header, `max_queue` is `outbound_queue_bytes`, and `max_peers` the cap on peers. The shared bounds (a day, the smallest frame) live in `louise_rt_prims::wire`. |
| 203 | 203 | |
| 204 | | −**Trust.** The decoder guarantees well-formed values of the type the frame names. It cannot check that a local mailbox's tag expects that type, because there is no table of exported subjects (see the alternatives). A malicious or buggy authenticated peer can therefore confuse a mailbox's types, as an Erlang peer can send anything. This is accepted under the trust model and needs engineering review. A per-actor record of exported (tag, hash) is the candidate mitigation. The node table (2^16 entries) only grows: each peer name may add 1,024 entries, its own incarnations included, and frames past that are dropped and counted. With links, monitors, `kill`, `stop` and spawns, an authenticated peer can also kill or stop any local actor by serial, grow an actor's links and monitors without bound, queue lookup answers and tie signals on the uncapped signal lane, and spawn any `@remote` entry with any argument of its type: all within the trust model, and all for the security review. With mesh discovery a peer can also direct this node's dials: up to `max_peers` addresses of its choice, each redialed with backoff until 10 × `node_down_after_ms` after it stops listing them. It cannot impersonate a node, since TLS checks the dialed name, but it can delay discovery of a node by listing a wrong address before that node confirms its own. Each up peer's latest list is kept (at most `max_peers` names), so lists hold at most `up peers × max_peers` names. |
| 204 | +**Trust.** The decoder guarantees well-formed values of the type the frame names. It cannot check that a local mailbox's tag expects that type, because there is no table of exported subjects (see the alternatives). A malicious or buggy authenticated peer can therefore confuse a mailbox's types, as an Erlang peer can send anything. This is accepted under the trust model and needs engineering review. A per-actor record of exported (tag, hash) is the candidate mitigation. The node table (2^16 entries) only grows: each peer name may add 1,024 entries, its own incarnations included, and frames past that are dropped and counted. With links, monitors, `kill`, `stop` and spawns, an authenticated peer can also kill or stop any local actor by serial, grow an actor's links and monitors without bound, queue lookup answers and tie signals on the uncapped signal lane, and spawn any `@remote` entry with any argument of its type: all within the trust model, and all for the security review. With mesh discovery a peer can also direct this node's dials: up to `max_peers` addresses of its choice, each redialed with backoff until 10 × `node_down_after_ms` after it stops listing them. It cannot impersonate a node, since TLS checks the dialed name, but each wrong address it lists costs one failed dial per turn until that node confirms its own; a black-hole address costs `node_down_after_ms` per turn, during which simultaneous-dial arbitration may refuse that node's own dial. A discovered node that has neither come up nor confirmed its address is on probation, held against the share (`max_peers` over the peers that send lists) of the lister whose list brought it; when all `max_peers` slots are taken, a new name takes the place of a node no lister holds, or of a probation node of a lister past its share. So one peer can fill its own share with dead names, not every slot. Each up peer's latest list is kept (at most `max_peers` names), so lists hold at most `up peers × max_peers` names. A round of lists still writes `n` lists of `n` names (523 MiB at 4,096 peers): sending changes instead would need a wire change. |
| 205 | 205 | |
| 206 | 206 | **Runtime.** |
| 207 | 207 | - Encoding happens on the sender's thread. The send hook borrows the message, and a remote send skips the send walk, since encoding copies anyway and `Wire` implies `Send`. |
| 208 | 208 | - The hook table has `send`, `link`, `monitor`, `down` (a local actor's `Down` to a remote watcher) and one `signal` hook (kill, stop, a link's exit). Hooks run on the actor's thread and never park, except `send`, through `dist::send_parking`. |
| 209 | | −- **The hooks do the whole remote job** (#412). `link` and `monitor` take the scheduler and the running actor, make its half (`dist::outbound`), list it in the node's `Dist`, and send the frame; `monitor` answers whether it made one, and if not the caller answers `noproc`. `exit` unlists an exiting actor that `Ties::nodes` ties to a node. `send`'s error is the sender's finished panic message. Without hooks, a remote pid is a dead one, as before. While the transport is stopping, a remote `monitor` answers `noproc` and a remote `link` is not made. An actor tied by an inbound frame after the transport starts but before the hooks are installed is not unlisted at its exit; it stays listed until its node is lost, and the fan-out skips it as gone. |
| 209 | +- **The hooks do the whole remote job** (#412). `link` and `monitor` take the scheduler and the running actor, make its half (`dist::outbound`), list it in the node's `Dist`, and send the frame; `monitor` answers whether it made one, and if not the caller answers `noproc`. `exit` unlists an exiting actor that `Ties::nodes` ties to a node. `send`'s error is the sender's finished panic message. Without hooks, a remote pid is a dead one, as before. While the transport is stopping, a remote `monitor` answers `noproc` and a remote `link` is not made. What peers send (node up and down, messages, signals) waits on the relay thread at a gate that `start` opens once it has published the node and installed the hooks, so no inbound tie is made before an actor's exit can unlist it. |
| 210 | 210 | - A remote exit through a link, or a remote `Down`, counts only if the local tie still exists, so node-down fan-out and the transport's own answer cannot both deliver. At a node-down, each tied actor (in pid order) gets its link exits, then its monitors' `Down`s. |
| 211 | 211 | - Linking to a remote pid with no transport does nothing, as linking to a dead local pid does today. With a transport, **a remote link or monitor of an actor that is gone answers `Crashed("noproc")`**, as Erlang does: the actor may exit while the link is on its way, and silence would leave the linker believing it is linked. Locally, linking to a dead pid still does nothing. |
| 212 | 212 | - The scheduler's `find_work` takes from the shared queue first one time in 61 when it holds actors, so an actor woken by the transport thread cannot starve behind a busy local queue: +0.085% instructions on `tests/bench/messages`. |
| @@ -229,3 +229,12 @@ The security review found two blocking and four major problems; the concurrency |
| 229 | 229 | - **A cap on peers** (`[cluster] max_peers`, #416). `Thread::hello` checks it after the version, ALPN, name, cluster, schema and frame-limit checks: before `arbitrate` on the acceptor, so no hello goes out, and before the ACK on the dialer. It counts connections whose hello was accepted. A stranger past the cap gets new refusal code 8, `Full`, logged through the throttled pre-hello path. Exempt: seeds and `connect`ed names (operator intent, so a full node still reaches its seeds) and a name that already has a connection past its hello (a new incarnation, or a duplicate). Discovered names are not exempt. `State.quotas` stays as it is, on purpose (forgetting a quota would reset SEC-5's budget); it holds one count per name that was ever up, bounded by the distinct CA-signed names that connect over the run, not by `max_peers`. |
| 230 | 230 | - **Deferred:** `spawn_monitor_on` (op `23`); unlink; refusing a peer whose runtime lacks an op (a capability flag per op). |
| 231 | 231 | |
| 232 | +### After the second reviews |
| 233 | +A security review and a concurrency review of #411 to #417 and the refcount fix found one blocking and three major security problems and two blocking concurrency ones. Each fix has a regression test that fails without it. |
| 234 | + |
| 235 | +- **`process.Selector` is opaque** (SR2-0). It had been a public record since #8: a program could take a selector's `Dynamic → m` map and rebind it to another subject's tag, so `select` returned an `Int` typed as a `String` (SIGSEGV natively), from std alone. The opaque `Subject` above relies on this. Open: any program can still import `std/wire`; `wire.arg` and `wire.dispatch` are safe given the opaque `Arg`, but enforcing that the module is internal needs a visibility feature. |
| 236 | +- **Discovery** (SR2-1, SR2-6, SR2-4, SR2-2, SR2-8, SR2-3): the budget shared by listers, the listers' addresses taken in turn, one shared list per round and one waiting per peer, long lists cut, hearsay dials kept out of `failures` (above, and Trust). When the slots are full, a list's names stop looking for room after the first that finds none, so a frame costs one scan of the known nodes, not one per name. |
| 237 | +- **The hooks' start window** (SR2-7) is closed by the gate (Runtime, above). |
| 238 | +- **A link listed under the actor's lock** (CC2-1, above). |
| 239 | +- **`std/table`'s and the builders' counts** (CC2-2): a shared value's count is only read through `heap::rc`, a relaxed atomic load, including the builders' `reserve`, `tl_bytes_build` and `tl_bytes_build_string`, which #407 had left as plain reads. `tests/run/shared_builder.lse` fails `scripts/tsan.sh` without it. |
| 240 | +- **Deferred** (SR2-5): op `16` scans the actor's monitors on `louise-dist-in`; with a million monitors held, one costs 580 µs. Indexing `Ties::monitors` (in the loom-modelled OTP core) or capping the remote monitors one peer holds on one actor is for the engineering review. Also open: a discovered node's confirmed address does not decay while it is down, so one that restarts on another port is reached when it dials in, or once forgotten. |