Skip to content

Fix message store crash when file deleted during concurrent GC#15411

Merged
michaelklishin merged 1 commit intorabbitmq:mainfrom
amazon-mq:fix/msg-store-missing-file-case
Feb 9, 2026
Merged

Fix message store crash when file deleted during concurrent GC#15411
michaelklishin merged 1 commit intorabbitmq:mainfrom
amazon-mq:fix/msg-store-missing-file-case

Conversation

@lukebakken
Copy link
Copy Markdown
Collaborator

During high load operations (such as maintenance drain with heavy queue leadership transfers), the message store can crash with {case_clause, {false, []}} in write_action/3 at line 1121.

This occurs when:

  1. A message exists in the index with ref_count=0 referencing file N
  2. File N is marked for deletion (valid_total_size=0)
  3. The garbage collector asynchronously deletes file N from FileSummaryEts
  4. A write operation attempts to look up file N
  5. ets:lookup(FileSummaryEts, N) returns []
  6. No case clause matches {false, []}

The crash cascades to queue processes attempting to write messages.

Solution

Add two new case clauses to write_action/3 to handle files already deleted by GC:

  • {false, []} - Delete stale index entry and write fresh copy to current file
  • {false_if_increment, []} - Ignore write when client is dying

This follows the same pattern as existing clauses that handle files being deleted or locked. Since ref_count=0, the old copy is orphaned and should be safe to discard.

@lukebakken lukebakken self-assigned this Feb 6, 2026
@lukebakken
Copy link
Copy Markdown
Collaborator Author

I appreciate the review @lhoguin - thanks!

Handle case where garbage collector asynchronously deletes a file from
FileSummaryEts while a write operation is trying to reference it. This
race condition can occur during high load (e.g., maintenance drain with
heavy queue leadership transfers) when:

1. Message exists in index with ref_count=0, file=N
2. File N is marked for deletion (valid_total_size=0)
3. GC asynchronously deletes file N from FileSummaryEts
4. Write request arrives for the message
5. ets:lookup(FileSummaryEts, N) returns []
6. Code crashes with {case_clause, {false, []}}

The fix adds two new case clauses to handle this scenario:

- {false, []} - Delete stale index entry and write fresh copy
- {false_if_increment, []} - Ignore write (client dying)

This follows the same pattern as existing clauses that handle files
being deleted or locked. Since ref_count=0, the old copy is orphaned
and safe to discard.

Observed in production during maintenance window causing 969 queue
process crashes. See ticket V2090892319.
@lukebakken lukebakken force-pushed the fix/msg-store-missing-file-case branch from e1fb5b7 to 8f27887 Compare February 6, 2026 20:56
@michaelklishin michaelklishin added this to the 4.3.0 milestone Feb 7, 2026
Copy link
Copy Markdown
Contributor

@lhoguin lhoguin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine.

Tbh I think this write_action clause may only be necessary anymore when there's older data because we index_delete on remove now. Or perhaps I just missed something.

@michaelklishin michaelklishin merged commit 5304c89 into rabbitmq:main Feb 9, 2026
290 of 291 checks passed
@lukebakken lukebakken deleted the fix/msg-store-missing-file-case branch February 9, 2026 15:33
michaelklishin added a commit that referenced this pull request Feb 9, 2026
Fix message store crash when file deleted during concurrent GC (backport #15411)
lukebakken pushed a commit to lukebakken/rmq-rabbitmq-server that referenced this pull request Mar 17, 2026
…g-file-case

Fix message store crash when file deleted during concurrent GC

(cherry picked from commit 5304c89)
lukebakken pushed a commit to lukebakken/rmq-rabbitmq-server that referenced this pull request Mar 17, 2026
…g-file-case

Fix message store crash when file deleted during concurrent GC

(cherry picked from commit 5304c89)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants