AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 53 Bitcoin

actor: never park sends made from inside a receive turn

Public commit record

What the developer wrote

Authored by Olaoluwa Osuntokun

90/100 · Strong
actor: never park sends made from inside a receive turn

In this commit, we make a send issued from an actor's own receive turn
non-blocking. Parking an actor on a full mailbox stalls its whole
mailbox, and a cycle of actors that do so deadlocks.

The actor loop now stamps the context handed to the behavior with a
turn marker, which is cleared when the turn returns. A Tell or Ask made
with such a context goes through a new in-turn path on the default
ChannelMailbox: it uses the channel when there is room and nothing is
queued ahead of it, and otherwise spills into a bounded overflow queue
that the receive loop refills the channel from, oldest first.

The queue is capped at ActorConfig.MailboxOverflowLimit, defaulting to
DefaultMailboxOverflowLimit. A send at the cap fails with
ErrMailboxOverflow, which an Ask surfaces on its Future. Tell can't
return an error, so it logs the drop. A context that outlives its turn,
in a goroutine the behavior spawned, parks like any other producer.
WithoutTurn clears the marker explicitly.

Delivery order is acceptance order. TrySend reports full while the
overflow is non-empty, and an ordinary blocking Send from outside the
actor first waits for the overflow to drain instead of writing to the
channel ahead of it. An owner can therefore enqueue a shutdown or
barrier message and know it runs after everything already accepted.
Drain yields the overflow after the channel.

The Mailbox interface is unchanged: the in-turn path is an optional
interface that ChannelMailbox implements.

This is ported from the in-turn send design in wavelength's
baselib/actor, with the Send ordering added.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This commit fixes a design flaw in LND's internal actor framework where an actor could freeze itself by sending a message to another actor whose mailbox was full. If several actors did this in a circle, the whole group could deadlock. The fix marks messages sent during an actor's own processing turn as 'in-turn' and routes them through a special non-blocking overflow queue, so the actor never stops moving. It also preserves message order and adds a hard cap so runaway message floods fail loudly instead of consuming unlimited memory.

Recommended action

Review the new lock ordering (mu then overflowMu) and the Close path to ensure no inversion or missed wakeups. Audit existing behaviors that spawn goroutines and pass the receive context, confirming they use WithoutTurn where appropriate. Run the new overflow and cycle tests under the race detector. Consider whether 100,000 default overflow limit is appropriate for production node memory constraints.

Security signals we found

01

Deadlock elimination in actor message-passing core

02

Bounded overflow queue prevents unbounded memory growth under overload

03

New error path ErrMailboxOverflow for explicit failure instead of silent blocking

04

Context turn marker could be misused if behavior passes turn context to a long-lived goroutine without WithoutTurn

05

Lock ordering and close-path changes in mailbox.go require careful concurrency review

Risk score

Why this scored 53/100

Our methodology →
Potential impact 18/30
Exploitability 5/25
Stealth signal 8/15
Affected reach 10/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.