Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog.d/6832.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- **A cut close of the security notifier records the notices it left unsent.** When the shutdown
cut `SecurityEventNotifier.aclose` while a send waited on a slow relay, the notices still queued
got no audit row, and on a full queue the drain ran on past the close. The close now stops
waiting for its drain at part of the shutdown step's bound, cancels it, and records the cut send
with `reason: interrupted` and each queued notice with `reason: abandoned`, and logs how many were
queued. A send still waiting for a worker thread at the cut is skipped, never mailed, and
recorded `abandoned`. The writes are not bounded, so under a full queue many can still be lost to the store's
close; [SECURITY.md](../docs/SECURITY.md) keeps that as an open residual. (`BACKLOG #6832`)
27 changes: 20 additions & 7 deletions docs/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7960,18 +7960,21 @@ same drops give totals one apart by lane.
when the notice is handed to the relay. It reads `mailed: true` only when the relay queued the
notice: one its full queue dropped, or one it refused because it had begun to close, reads
`mailed: false`, so the next lock of the kind mails again (vault BACKLOG #3120). When the relay's queue is full, the relay refuses the notice because it has
begun to close, or the send fails, the engine writes one more row, with the notice's recipient as
the actor. A lock
begun to close, a cut close leaves the notice queued or cuts its send, or the send fails, the
engine tries to write one more row, with the notice's recipient as the actor; when that write
can fail is under *Still open* below. A lock
notice writes `auth.lock_notice_undelivered`, hidden as above. Every other notice kind writes
`auth.security_notice_undelivered`, which every `audit:read` reader sees. The detail names the
notice kind and the `reason`, `queue_full`, `closing` or `send_failed`. An issuer's reminder also names the
notice kind and the `reason`, at least `queue_full`, `closing`, `abandoned`, `interrupted` or
`send_failed`. An issuer's reminder also names the
holder. The row never carries the address, the rest of the notice's detail, or the error. The
source of record is `SecurityEventNotifier._record_undelivered` in
`messagefoundry/pipeline/security_notify.py`. At least the offline commands `provision-admin` and
`admin-reset-totp` record it the same way (BACKLOG #5634). `provision-admin` writes it into the
store it holds open, so a takeover notice whose `auth.first_administrator_provisioned` row reads
`holder_notice: dispatched` and whose send failed gets its own undelivered row too, except in at
least these cases: that write fails, or the run is interrupted mid-send. The command's own result
least these cases: that write fails, or an interrupt ends the run before it lands. An interrupt
mid-send can instead leave a `reason: interrupted` row (BACKLOG #6832). The command's own result
says so as well: `holder_notice_send_failed` in `--json`, and a WARNING line in text. Both say
the notifier requested to record the notice as undelivered, that is, its send raised, so delivery is
unconfirmed; a send can raise after the relay has queued the mail. That row can
Expand All @@ -7980,9 +7983,19 @@ come before the provision row in the chain, because the notice is sent while the
again for the row, and only when a send failed. **Still open, at least:**

- At shutdown the notifier closes while the store is still open (BACKLOG #3191), so a send that
fails in its final drain is recorded. That close is one bounded step of the shutdown. When the
step is cut, a notice still queued is neither sent nor recorded, and a send already under way
may still go out or fail unrecorded. A lock notice among them keeps its `auth.lock_notice` row
fails in its final drain is recorded. That close is one bounded step of the shutdown. The close
stops waiting for its drain at part of that step's bound, or when the step is cut, then cancels
the drain and records the send it cut with `reason: interrupted` and each notice still queued
with `reason: abandoned` (BACKLOG #6832). A send still waiting for a worker thread at the cut
is skipped, so it never mails, and is recorded `abandoned` too; one that ended just before the
cut is recorded as it ended. A cut send whose thread began runs on to its own timeout, so that
notice may still go out. Those writes run one at a time and are not bounded. The shutdown
stops waiting for them at the step's bound plus its cut grace; the rest go on beside
`engine.stop()`, competing with its writes, until the store closes, and those still to run then
fail. Under a full queue that can be most of them. A WARNING line counting the queued notices
comes before their writes, and one counting the writes that failed comes after; it does not
count the writes a cancel stopped before they ran. Neither line counts a lock notice. A lock
notice among them keeps its `auth.lock_notice` row
reading `mailed: true`, so the throttle holds back that account's next lock notice of the kind
for the rest of its 24 hours.
- A notice that reaches the notifier once it has begun to close is refused and recorded with
Expand Down
14 changes: 8 additions & 6 deletions messagefoundry/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9651,11 +9651,13 @@ def run() -> None:
class _CountingNoticeAudit:
"""A :class:`NoticeAuditSink` that forwards to ``inner`` and counts the undelivered records the
notifier asked for, so ``provision-admin`` can say that delivery of a notice it reported as
dispatched is unconfirmed (BACKLOG #5634). For a dispatched notice the notifier records only a
send that raised, so a count above zero is one, whether or not the forwarded write then
succeeded. A send can raise after the relay queued the mail, so it is not proof the notice
never left. A count of zero is not a delivery receipt: at least a drain ended by an interrupt
asks for no record."""
dispatched is unconfirmed (BACKLOG #5634). For a dispatched notice the notifier records a send
that raised, and, when its close is cut, the send it cut or the notice it left queued (BACKLOG
#6832); at least an interrupt cuts this command's close, and it ends the run before the count
is read. So a count above zero says delivery is unconfirmed, whether or not the forwarded write
then succeeded. A send can raise after the relay queued the mail, so it is not proof the notice
never left. A count of zero is not a delivery receipt: a send that returned says only that the
relay took the mail."""

def __init__(self, inner: NoticeAuditSink) -> None:
self._inner = inner
Expand Down Expand Up @@ -11543,7 +11545,7 @@ async def alert() -> bool:

# BACKLOG #5634: the notifier drained before run() returned, so its count is final here. None
# unless a notice was dispatched. False is not a delivery receipt: it says only that the
# notifier recorded no undelivered notice, and at least a drain ended by an interrupt records none.
# notifier recorded no undelivered notice, and a send that returned says only the relay took it.
holder_send_failed: bool | None = (
bool(notice_audit) and notice_audit[0].undelivered > 0
if outcome.holder_notice == HOLDER_NOTICE_DISPATCHED
Expand Down
6 changes: 5 additions & 1 deletion messagefoundry/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,11 @@ def _managed_teardown_steps(
# #3191).
steps.append(
_TeardownStep(
"the security notifier's close", 0.25, lambda _b: security_notifier.aclose()
"the security notifier's close",
0.25,
# Part of the bound, so the close cuts its own drain and starts recording the
# notices it left before the step is cut (BACKLOG #6832).
lambda b: security_notifier.aclose(b * _INNER_SHARE),
)
)
# This takes the observers off. An unpinned cluster node's posture inverse is not raised here,
Expand Down
6 changes: 4 additions & 2 deletions messagefoundry/pipeline/alert_sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2610,8 +2610,10 @@ async def aclose(self) -> None:
was never started. A close cancelled while its sentinel waits on a full queue cancels the
delivery task too and waits for it (BACKLOG #5907), so the startup unwind's cut does not
leave the drain running after the store closed; a send that outlives the drain's grace is
still left running (:meth:`_cut_sends`). Only this sink does that: an undelivered alert is
counted by :attr:`undelivered`, while a security notice's loss must reach its audit row."""
still left running (:meth:`_cut_sends`). The security notifier's close cancels its drain
too, and then starts recording, where it has an audit sink, each notice the cut left
unsent (BACKLOG #6832); a write that meets the closed store is lost,
while an undelivered alert is counted by :attr:`undelivered`."""
drain = self._task
try:
await super().aclose()
Expand Down
Loading
Loading