Skip to content

fix(Foundation): Fix FileChannel purge race with compression#5116

Merged
matejk merged 1 commit intomainfrom
4848-file-channel-purge-race
Dec 18, 2025
Merged

fix(Foundation): Fix FileChannel purge race with compression#5116
matejk merged 1 commit intomainfrom
4848-file-channel-purge-race

Conversation

@matejk
Copy link
Copy Markdown
Contributor

@matejk matejk commented Dec 17, 2025

Summary

Fixes #4848 (and completes the fix for #2439).

The previous fix (commit 9aec797) synchronized log rotation with compression by waiting for previous compressions to complete. However, purge() was still called immediately after archive() returned, while the new compression was still running in the background. This race condition could cause incorrect file counts during purging.

Changes

ArchiveStrategy.h:

  • Added PurgeCallback type and setPurgeCallback() method
  • Fixed ArchiveByTimestampStrategy::archive() - added missing _rotateMutex lock and compression wait (was completely unsynchronized)

ArchiveStrategy.cpp:

  • Invoke purge callback when all compressions complete (in compressFile())
  • Invoke purge callback at end of archive() if no compression was started

FileChannel.cpp:

  • Set purge callback on archive strategy in constructors and setters
  • Removed direct purge() calls from log() and open() - now handled via callback

FileChannelTest.cpp:

  • Fixed testCompressedRotation expectations: with purgeCount=5, expect 5 archives (was incorrectly expecting 6 due to the race condition)

How it works

  • When compression is enabled: purge callback fires after compression completes (in compression thread, under _rotateMutex)
  • When compression is disabled: purge callback fires at end of archive() (under _rotateMutex)
  • No additional blocking in the logging thread
  • All purge operations are properly serialized with rotation and compression

Test plan

  • FileChannelTest passes (12 tests including testCompressedRotation)
  • testPurgeCount passes

@matejk matejk merged commit e8745d0 into main Dec 18, 2025
86 checks passed
@matejk matejk deleted the 4848-file-channel-purge-race branch December 18, 2025 09:58
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.

Foundation: FileChannel purge race condition with compression (#2439)

1 participant