Skip to content

Foundation: Synchronize channel replacement and prevent FileChannel data races - #5509

Open
Tyagiquamar wants to merge 1 commit into
pocoproject:mainfrom
Tyagiquamar:fix/channel-race-synchronization
Open

Tyagiquamar wants to merge 1 commit into
pocoproject:mainfrom
Tyagiquamar:fix/channel-race-synchronization

Conversation

@Tyagiquamar

Copy link
Copy Markdown

Summary

This PR addresses thread-safety issues during dynamic channel replacement and logging in POCO Foundation:

  1. Logger Channel Synchronization:

    • Added _channelMutex in Poco::Logger guarding channel assignment (setChannel) and retrieval (getChannel).
    • Logging paths now acquire a local Channel::Ptr reference under getChannel() before invoking pChannel->log(...), ensuring active message logging remains valid even if another thread resets or changes the channel concurrently.
  2. FormattingChannel Synchronization:

    • Added mutex protection over _pFormatter and _pChannel accessors and mutators in Poco::FormattingChannel.
    • Thread-safe property forwarding and channel invocation.
  3. FileChannel Mutex Scope:

    • Extracted internal unsafeOpen() to ensure file handle initialization and rotation checks occur under the existing _mutex lock in FileChannel::log(), avoiding race conditions between open and log operations across concurrent threads.
  4. Unit & Concurrency Tests:

    • Added testConcurrentChannelReplacement and testConcurrentShutdown to Foundation/testsuite/src/LoggerTest.cpp verifying stability under multi-threaded channel mutation.

Validation

  • Clean build in Docker (ubuntu:noble).
  • Foundation-testrunner LoggerTest executed and passed 100% (9/9 tests OK).

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