Skip to content

prowld: stop handling requests while a client's replies back up - #708

Merged
laffer1 merged 1 commit into
masterfrom
prowld-ipc-backpressure
Nov 29, 2026
Merged

laffer1 merged 1 commit into
masterfrom
prowld-ipc-backpressure

Conversation

@laffer1

@laffer1 laffer1 commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Summary

prowld kept reading and answering a client's requests even while that client's earlier replies were still unsent. A client that pipelined requests without reading the replies made PID 1 queue up to IPC_OUT_MAX (8 MiB) for it. After that, further replies were silently dropped, and the client waited for them until its own timeout. jemalloc keeps the memory afterwards: in a test guest, 200 pipelined list requests left PID 1 at 45 MB for the rest of the boot.

This change adds a high-water mark, IPC_OUT_HIWAT (1 MiB):

  • Once more than 1 MiB is queued for a client (out_held), its requests are no longer dispatched. Dispatch resumes when the queue drains below the mark, in ipc_write_ready().
  • The held requests are still read into the client's receive buffer. Only a full buffer (IPC_MSG_MAX) stops reading, using the same NOTE_LOWAT hold that service actions use. Stopping reads any earlier deadlocked test clients that write a batch of requests before reading: they were blocked in write() while prowld waited for them to read.
  • Resuming is shared with the end of a service action, in the new ipc_resume_client().
  • A held client is exempt from the 30-second frame timeout while it waits.

A client can still stall itself, but only by sending more than 64 KiB of requests while leaving more than 1 MiB of replies unread. prowlctl sends one request at a time, and the socket is root:wheel 0660.

Testing

In a bhyve guest with each binary as PID 1, running 190 jobs (the shipped units, the rc.d scripts and test units):

Check master this branch this branch, junk:true,abort:true
200 pipelined list requests, unread for 8 s (×3) 199/200 replies each time 200/200 200/200
PID 1 RSS during and after the flood 44.9 MB, stays at 45 MB 4.7–4.8 MB 4.7–4.8 MB
Half-close after 100 requests; slow reader; actions pipelined with list pass pass pass
Existing IPC tests: 3 × 64 KiB pipelined, 30 clients, dripped frame, over-limit frame pass pass pass
list/show/graph, check/resync actions, before and after the load pass pass pass

The first two versions of this change hung in these tests:

  • Holding reads as soon as any output was pending deadlocked the 3 × 64 KiB test.
  • Holding reads at the 1 MiB mark deadlocked the flood test.

The version here passed 17/17 checks on both branch runs.

The build is clean with -Werror, and checkstyle9.pl is clean.

Review notes

No allocations change. Per AI_POLICY.md, the parts to audit are the state transitions:

  • out_held is set in ipc_send(), cleared in ipc_write_ready() and reset in ipc_close_client().
  • The held-read branch in ipc_read_client(), which runs before the receive buffer grows, so a full buffer is never treated as an oversized frame.
  • The close-after-EOF path in ipc_write_ready(), which now waits until held requests are handled and no action is running.

AI-Assisted-by: Claude Opus 5.5

🤖 Generated with Claude Code

prowld kept reading and answering a client's requests even while earlier
replies were still unsent.  A client that sent many requests without
reading the replies made PID 1 queue up to IPC_OUT_MAX (8 MiB) for it,
after which further replies were dropped and the client was left waiting
for them.  jemalloc keeps that memory: in a test guest, 200 pipelined
"list" requests left PID 1 at 45 MB instead of 2.7 MB.

Once more than IPC_OUT_HIWAT (1 MiB) is queued for a client, stop
dispatching its requests until the queue drains below that again.  The
requests are still read into the receive buffer, so a client that is
blocked writing a batch of requests can get to its replies; reading
stops only when the receive buffer is full (IPC_MSG_MAX).  Resuming
after the queue drains shares ipc_resume_client() with the end of a
service action.

Tested in a bhyve guest with this prowld as PID 1, also with
malloc.conf junk:true,abort:true: 200 pipelined "list" requests left
unread for 8 seconds all got their replies, with PID 1 at about 4.8 MB.
Half-closed and slow-reading clients, actions pipelined with "list", and
the existing IPC load tests pass.

AI-Assisted-by: Claude Opus 5.5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lucas Holt <luke@foolishgames.com>
@sourcery-ai

sourcery-ai Bot commented Nov 29, 2026

Copy link
Copy Markdown

Sorry @laffer1, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 2 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@laffer1
laffer1 merged commit ade1f48 into master Nov 29, 2026
9 of 12 checks passed
@laffer1
laffer1 deleted the prowld-ipc-backpressure branch November 29, 2026 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant