[Backport][main to 0.9] | fix(alog): prevent child deadlock on rotation lock across fork() (#1573) - #1575
Merged
lihuiba merged 1 commit intoJul 28, 2026
Conversation
The log rotation mutex was a function-local static in write(). If fork() happened while another thread was rotating, the child inherited the mutex permanently locked and deadlocked on its next rotation. Hoist the lock to file scope and serialize it against fork() with pthread_atfork(): prepare acquires it (waiting out any in-flight rotation), and both parent and child release it afterwards. Add a fork-during-rotation regression test.
lihuiba
approved these changes
Jul 28, 2026
photonlibos
deleted the
backport-pr-f31e619440ae9e11e9abf939600a28ca791b71a7-0.9
branch
July 28, 2026 11:07
lihuiba
pushed a commit
that referenced
this pull request
Jul 28, 2026
…) (#1575) (#1577) The log rotation mutex was a function-local static in write(). If fork() happened while another thread was rotating, the child inherited the mutex permanently locked and deadlocked on its next rotation. Hoist the lock to file scope and serialize it against fork() with pthread_atfork(): prepare acquires it (waiting out any in-flight rotation), and both parent and child release it afterwards. Add a fork-during-rotation regression test. Co-authored-by: Coldwings <coldwings@me.com>
lihuiba
pushed a commit
that referenced
this pull request
Jul 29, 2026
…n lock across fork() (#1573) (#1575) (#1577) (#1579) * fix(alog): prevent child deadlock on rotation lock across fork() (#1573) (#1575) (#1577) The log rotation mutex was a function-local static in write(). If fork() happened while another thread was rotating, the child inherited the mutex permanently locked and deadlocked on its next rotation. Hoist the lock to file scope and serialize it against fork() with pthread_atfork(): prepare acquires it (waiting out any in-flight rotation), and both parent and child release it afterwards. Add a fork-during-rotation regression test. Co-authored-by: Coldwings <coldwings@me.com> * Update alog.cpp --------- Co-authored-by: Coldwings <coldwings@me.com>
lihuiba
added a commit
that referenced
this pull request
Jul 30, 2026
…ion lock across fork() (#1573) (#1575) (#1577) (#1579) (#1582) * [Backport][0.8 to 0.7] | fix(alog): prevent child deadlock on rotation lock across fork() (#1573) (#1575) (#1577) (#1579) * fix(alog): prevent child deadlock on rotation lock across fork() (#1573) (#1575) (#1577) The log rotation mutex was a function-local static in write(). If fork() happened while another thread was rotating, the child inherited the mutex permanently locked and deadlocked on its next rotation. Hoist the lock to file scope and serialize it against fork() with pthread_atfork(): prepare acquires it (waiting out any in-flight rotation), and both parent and child release it afterwards. Add a fork-during-rotation regression test. Co-authored-by: Coldwings <coldwings@me.com> * Update alog.cpp --------- Co-authored-by: Coldwings <coldwings@me.com> * Update test_alog.cpp * Update test_alog.cpp --------- Co-authored-by: Coldwings <coldwings@me.com> Co-authored-by: Huiba Li <huiba.lhb@alibaba-inc.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The log rotation mutex was a function-local static in write(). If fork() happened while another thread was rotating, the child inherited the mutex permanently locked and deadlocked on its next rotation. Hoist the lock to file scope and serialize it against fork() with pthread_atfork(): prepare acquires it (waiting out any in-flight rotation), and both parent and child release it afterwards. Add a fork-during-rotation regression test.
Generated by Backport Auto PR, by cherry-pick related commits.
Please review and decide whether to merge or close this backport PR.