GeezerVison is showing github.com — chat: broadcast fan-out runs each Send in its own goroutine — messages arrive out of order and a stalled session piles up unbounded blocked goroutines · Issue #4389 · developing-today/code
chat: broadcast fan-out runs each Send in its own goroutine — messages arrive out of order and a stalled session piles up unbounded blocked goroutines #4389Labels app/chatPackage/app: chat (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/triageQueue packet kind: verify, reproduce, and route this item DescriptionProblem
app.send in pkgs/chat/main.go fans a chat message out with one new goroutine per recipient (go p.Send(msg), main.go:52-54). Nothing serializes those goroutines, so:
- Broadcast order is not preserved. Two messages sent in order can be delivered to a session in the opposite order whenever the first
Send is delayed (a busy program, scheduler timing). Different sessions can therefore show the same conversation in different orders, and one session can show a reply before the message it answers.
- A stalled session accumulates unbounded goroutines.
tea.Program.Send blocks until the program's update loop reads the message (or the program ends). A session that stops reading — a wedged terminal, a dead-but-not-yet-pruned connection — leaves one blocked goroutine per broadcast message, forever, with no bound, coalescing, or drop.
Evidence (main @ 30ce6be, verified this run)
pkgs/chat/main.go:46-55 — send copies the registry under RLock, then for _, p := range progs { go p.Send(msg) }. The go is presumably there because send is called from inside a model's Update (main.go:205-211) and the sender's own program is in the registry, so a naive synchronous Send to itself could block its own update loop — but the goroutine-per-recipient shape trades that for ordering and pile-up.
- Laptop probe (verbatim
main.go/main_test.go from current main, md5 main.go ed60f0ca59fe0cec95101087ca792655; probe dir ~/git/fleet/probe-2026-11-02-laneB-chatorder/ on the laptop):
- PROBE1: a recipient whose
Send for the text first sleeps 150 ms before recording received two broadcasts issued in order [first second] as [second first] — order inverted at one recipient.
- PROBE2: 40 broadcasts to one recipient whose
Send never returns grew the goroutine count by exactly 40 — one permanently blocked goroutine per message, unbounded.
- The existing registry tests (
TestSendReachesOnlyLivePrograms, TestRemoveUnknownIsNoOp, TestRegistryConcurrentRegisterSendRemove) all pass alongside the probes.
Why it matters
A chat room's one shared truth is the order of its messages. Today that order is per-session luck: two participants can read the same exchange in opposite orders with no error anywhere. And the pile-up half turns one stalled SSH session into slow, unbounded goroutine growth on the server for as long as the room stays busy — the registry pruning from #3201 only helps once the program actually ends, not while it is wedged.
Acceptance criteria
- Broadcasts are delivered to each live program in the order
send was called: a probe in the style of PROBE1 (a recipient whose first Send is delayed) records [first second], and a multi-recipient probe shows every recipient recording the same order.
- A recipient that never reads cannot accumulate goroutines without bound: the fan-out drops, coalesces, or queues with a stated bound for a stalled program (PROBE2-style measurement stays bounded as broadcasts continue), and the session is still pruned normally when its program ends.
- Sending a message from a session still delivers it to that same session (no self-send deadlock): the sender sees its own message exactly once, in order.
- Existing
pkgs/chat tests pass; new tests pin both the ordering and the bounded-stalled-recipient behaviour using the existing sender interface / fakeProg harness.
Distinct from #3201 (closed: registry never pruned — this is the fan-out call shape that fix kept, not the registry lifecycle) and from #3209 (graceful shutdown exits 1, the Start/ListenAndServe path, unrelated to send). Activityadded kind/bugSomething isn't working (prefixed form of the classic bug label) task/triageQueue packet kind: verify, reproduce, and route this item app/chatPackage/app: chat (pkgs/ or apps/ in this repo) effort/sSmall: expected under 2 hours of work on Nov 2, 2026dezren39 commented on Nov 2, 2026 🤖 Agent note · filed
- Agent: new-issue-creator (lane B, new-issue-creator-code-b)
- Session / ID: cron new-issue-creator-code-b, run 2026-11-02 08:20 CST
- Found via: filed this run
- Task: Triage issue chat: broadcast fan-out runs each Send in its own goroutine — messages arrive out of order and a stalled session piles up unbounded blocked goroutines #4389 — app.send (pkgs/chat/main.go:52-54) fans each broadcast out as
go p.Send(msg) per recipient, so delivery order is scheduler luck (two messages can arrive reversed at a session, and sessions disagree with each other) and a stalled session leaves one permanently blocked goroutine per broadcast, unbounded.
- Expectation: effort/s — confirm on current main (laptop probe at ~/git/fleet/probe-2026-11-02-laneB-chatorder/, verbatim main.go @30ce6be56 md5 ed60f0ca: PROBE1 recorded [second first] for broadcasts sent [first second]; PROBE2 grew goroutines by exactly 40 for 40 broadcasts to a never-reading recipient; existing registry tests pass), then route the fix (serialized fan-out with a stated bound/drop for stalled recipients; beware the self-send deadlock a naive synchronous Send would cause, since send is called from inside Update).
- Links: issue chat: broadcast fan-out runs each Send in its own goroutine — messages arrive out of order and a stalled session piles up unbounded blocked goroutines #4389; related (distinct) chat: session program registry never pruned — unbounded growth, per-message fan-out to dead programs, and a data race on the shared slice #3201 (registry pruning, closed) and chat: graceful shutdown always exits 1 — serve goroutine log.Fatalln's the expected ErrServerClosed, pre-empting the 30s drain #3209 (shutdown exit code)
dezren39 commented on Nov 2, 2026
Agent note — task 6272 triage verdict: CONFIRMED on current main (lane code-k)
- Fresh check on origin/main
381fecb60607b34288fea966c7ea5a3433310b29: pkgs/chat/main.go md5 ed60f0ca59fe0cec95101087ca792655 — byte-identical to the file this issue's probe exercised, so both probe results carry over unchanged (PROBE1 recorded [second first]; PROBE2: +40 goroutines after 40 broadcasts to a blocked recipient).
- Code read:
app.send (main.go:47-56) copies the registry under RLock, then runs go p.Send(msg) per program. Nothing serializes successive broadcasts to the same program, so delivery order per recipient is scheduler luck; and each broadcast to a stalled session parks one more goroutine in Send until that program ends — growth is unbounded and driven purely by room traffic.
- The registry lifecycle itself is sound (chat: session program registry never pruned — unbounded growth, per-message fan-out to dead programs, and a data race on the shared slice #3201 pruning verified in the same read:
remove drops finished programs; the gap is only the fan-out shape chat: session program registry never pruned — unbounded growth, per-message fan-out to dead programs, and a data race on the shared slice #3201 kept).
- Fix routed as task 6423 (small_fix): per-recipient serialized delivery preserving send order, a stated bound on stalled-recipient goroutines (drop/coalesce/bounded queue), self-send exactly once with no Update deadlock, and tests pinning both via the sender/fakeProg harness. Excludes chat: graceful shutdown always exits 1 — serve goroutine log.Fatalln's the expected ErrServerClosed, pre-empting the 30s drain #3209 per scope.
dezren39 commented on Nov 8, 2026 developing-today commented on Nov 8, 2026 🤖 Agent note · picked up
- Agent: repo queue worker, lane code-u (repo-worker-code)
- Session / ID: cron repo-queue-worker-shift-u run 2026-11-07 23:04 CST; task 12687
- Found via: queue claim · task 12687
- Task: task 12687 small_fix for issue chat: broadcast fan-out runs each Send in its own goroutine — messages arrive out of order and a stalled session piles up unbounded blocked goroutines #4389 — land PR fix(chat): preserve broadcast order with bounded recipient queues #4530 (fix(chat): preserve broadcast order with bounded recipient queues). Execution-lane assignment returned
direct. Fresh check: issue chat: broadcast fan-out runs each Send in its own goroutine — messages arrive out of order and a stalled session piles up unbounded blocked goroutines #4389 is OPEN with no hard-stop labels; PR fix(chat): preserve broadcast order with bounded recipient queues #4530 is OPEN, unlabeled, Codex review completed with no findings (no inline Codex comments), and its diff implements exactly the packet's intent (per-recipient serialized queue, depth 16, stalled recipients pruned; order + goroutine-bound tests included). pkgs/chat/main.go:55 on current main still runs go p.Send(msg). The one defect: PR fix(chat): preserve broadcast order with bounded recipient queues #4530 is CONFLICTING with current main, so this lane rebases its branch queue/6421-4389-chat-broadcast-order (fix-forward, per the packet), verifies the chat tests, and merges it.
- Expectation: PR fix(chat): preserve broadcast order with bounded recipient queues #4530 merged; issue chat: broadcast fan-out runs each Send in its own goroutine — messages arrive out of order and a stalled session piles up unbounded blocked goroutines #4389 closed by the PR's closing keyword or verified closure; task 12687 completed as
fixed_merged.
- Links: task 12687 · issue chat: broadcast fan-out runs each Send in its own goroutine — messages arrive out of order and a stalled session piles up unbounded blocked goroutines #4389 · PR fix(chat): preserve broadcast order with bounded recipient queues #4530
developing-today commented on Nov 8, 2026
MetadataMetadataapp/chatPackage/app: chat (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/triageQueue packet kind: verify, reproduce, and route this item DevelopmentNo branches or pull requestsIssue actions
|