Repository navigation
Fix close an unopened AOF file during shutdown - #15827
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 7964542. Configure here.
|
|
||
| # A rewrite can be scheduled but paused while another background task is running, | ||
| # so we need to check two conditions | ||
| if {$rewrite_in_progress eq 1 || $rewrite_scheduled eq 1} { |
There was a problem hiding this comment.
Rewrite wait samples flags non-atomically
Low Severity
waitForBgrewriteaof reads aof_rewrite_in_progress and aof_rewrite_scheduled via two separate INFO calls, in-progress first. If a scheduled rewrite starts between those queries, both flags can look cleared and the helper returns while the rewrite is still running.
Reviewed by Cursor Bugbot for commit 7964542. Configure here.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #15827 +/- ##
============================================
- Coverage 77.63% 77.24% -0.39%
============================================
Files 146 146
Lines 87994 87995 +1
============================================
- Hits 68314 67974 -340
- Misses 19680 20021 +341
🚀 New features to boost your workflow:
|
Yes, the PR15665 just added some tests, and Valgrind detected this |
ok, so it means that this bug exist for a long time, can you check it in the old version? |
I think PR #9788 changed when the AOF file is opened but did not update the close path accordingly.
|
Co-authored-by: Yuan Wang <[email protected]>


Issue
stopAppendOnly()unconditionally calledfsync()andclose()onserver.aof_fd. When AOF was inAOF_WAIT_REWRITE, the initial rewrite could be scheduled but not started because another background operation was still running. In that state, no AOF file had been opened andserver.aof_fdwas-1.Failed daily CI: https://github.com/redis/redis/actions/runs/35547037033/job/106174688222
The unconditional
close(server.aof_fd)was not introduced by PR #15665. #15665 introduced theaof_cmd_durationfeature and its test, which exercised this AOF lifecycle state.The CI failure occurred when the test disabled AOF before the scheduled rewrite had actually started. The test helper waited only for
aof_rewrite_in_progressand returned while the rewrite was still scheduled, exposing the existingclose(-1)bug during cleanup.Change
waitForBgrewriteaofto wait until bothaof_rewrite_in_progressandaof_rewrite_scheduledare cleared, preventing the test from disabling AOF while a rewrite is still pending.Test
The waitForBgrewriteaof method is used in many places. I runned the fully daily CI: https://github.com/vitahlin/redis/actions/runs/35679811939
Note
Medium Risk
Touches runtime AOF disable path in
stopAppendOnly(), which is safety-sensitive but the change is a narrow guard around fd I/O; broader test helper behavior may affect any suite that waits on AOF rewrites.Overview
Fixes a crash/invalid
close(-1)whenappendonlyis turned off at runtime while AOF is enabled but the first background rewrite is only scheduled (e.g. blocked by an in-flight BGSAVE), soserver.aof_fdis still -1.stopAppendOnly()now runs flush, fsync, and close only when a file descriptor is actually open; other shutdown steps (state reset, killing the rewrite child, etc.) are unchanged.Test support is tightened so
waitForBgrewriteaofwaits until bothaof_rewrite_in_progressandaof_rewrite_scheduledare clear, avoiding tests that disable AOF while a rewrite is still pending. A newaofrwtest covers enabling AOF under a slow BGSAVE, then disabling AOF before the initial rewrite starts.Reviewed by Cursor Bugbot for commit 42a6ebc. Bugbot is set up for automated code reviews on this repo. Configure here.