Skip to content

Fix stack overflow with circular or long dead-letter chains#1845

Open
spuun wants to merge 10 commits intomainfrom
bugfix/dlx-callstack-overflow
Open

Fix stack overflow with circular or long dead-letter chains#1845
spuun wants to merge 10 commits intomainfrom
bugfix/dlx-callstack-overflow

Conversation

@spuun
Copy link
Copy Markdown
Member

@spuun spuun commented Apr 8, 2026

WHAT is this pull request doing?

Dead-lettering was implemented via direct recursive calls, causing a stack overflow when two queues mutually dead-lettered to each other or when a sufficiently long dead-letter chain was traversed.

Changes:

  • Replaced recursive dead-letter routing with a trampoline pattern: the DeadLetterer now collects pending (queue, message, callback) tuples into a Context deque and drains them iteratively, keeping the call stack flat regardless of chain length
  • Added a routed callback to DeadLetterer#route so the source message is deleted only after it has been successfully enqueued at the destination (preserving message safety)
  • Introduced publish_internal on queues to accept and propagate the dlx_context through publish → drop_overflow → expire_msg → route, avoiding allocating a new context per hop
  • Moved drop_overflow calls triggered by policy updates into a spawned fiber to avoid re-entrancy

Supersedes #1721

HOW can this pull request be tested?

Specs

@spuun spuun requested a review from a team as a code owner April 8, 2026 11:23
@cloudamqp cloudamqp deleted a comment from claude bot Apr 9, 2026
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