Commit 08514ff
Fix segfault race condition when closing auto-delete queues (#1529)
## Summary
- Use WaitGroup to track active deliver loop fibers and wait for them to
complete before closing the message store
- Prevents race condition where MFile could be unmapped while a consumer
was still delivering a message (causing segfault in `properties.cr:224`
during `to_io()`)
- Reorder Consumer#close to close notification channels before calling
rm_consumer to prevent deadlock during auto_delete queue cleanup
## Background
When a heartbeat timeout triggers client cleanup on an auto-delete
queue, the following race can occur:
1. Consumer deliver loop is writing message headers to socket (which
yields)
2. Client cleanup triggers queue auto-delete → queue close → message
store close → MFile unmap
3. Consumer deliver loop resumes and tries to continue writing from
unmapped memory → SEGFAULT
The fix uses Crystal's WaitGroup to ensure all deliver loops have exited
before the message store is closed.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude <[email protected]>1 parent 75bcc5e commit 08514ff
2 files changed
+6
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | | - | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
| |||
414 | 415 | | |
415 | 416 | | |
416 | 417 | | |
417 | | - | |
| 418 | + | |
| 419 | + | |
418 | 420 | | |
419 | 421 | | |
420 | 422 | | |
| |||
0 commit comments