Skip to content

[Backport][main to 0.9] | fix(alog): prevent child deadlock on rotation lock across fork() (#1573) - #1575

Merged
lihuiba merged 1 commit into
release/0.9from
backport-pr-f31e619440ae9e11e9abf939600a28ca791b71a7-0.9
Jul 28, 2026
Merged

[Backport][main to 0.9] | fix(alog): prevent child deadlock on rotation lock across fork() (#1573)#1575
lihuiba merged 1 commit into
release/0.9from
backport-pr-f31e619440ae9e11e9abf939600a28ca791b71a7-0.9

Conversation

@photonlibos

Copy link
Copy Markdown
Collaborator

fix(alog): prevent child deadlock on rotation lock across fork() (#1573)

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.

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.
@photonlibos photonlibos added the bugfix A PR that should be back-ported to prior release branches (release/*) label Jul 28, 2026
@lihuiba
lihuiba merged commit 9243773 into release/0.9 Jul 28, 2026
24 checks passed
@photonlibos
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix A PR that should be back-ported to prior release branches (release/*)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants