Skip to content

preload: Reinitialize mutexes after forking#280

Merged
martinpitt merged 1 commit intomartinpitt:mainfrom
vanvugt:fix-deadlock-after-fork
Mar 22, 2026
Merged

preload: Reinitialize mutexes after forking#280
martinpitt merged 1 commit intomartinpitt:mainfrom
vanvugt:fix-deadlock-after-fork

Conversation

@vanvugt
Copy link
Copy Markdown
Contributor

@vanvugt vanvugt commented Mar 18, 2026

Or else there's a risk the child process has inherited mutexes that are already locked, resulting in a deadlock as soon as it tries to use them.

https://bugs.launchpad.net/bugs/2144723

@martinpitt
Copy link
Copy Markdown
Owner

Thanks @vanvugt ! I'm not familiar with that glibc on_load() constructor API magic. I'll do some RTFM, but also ask the robodude -- please don't take it as bad faith.

@martinpitt martinpitt requested a review from Copilot March 19, 2026 12:54
@martinpitt
Copy link
Copy Markdown
Owner

Ah nevermind, of course on_load() isn't magic at all. It's just a random name for the constructor. Makes sense!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a fork-safety issue in the libumockdev preload library by ensuring mutex state in the child process cannot remain inherited/locked, which could otherwise deadlock the child when it next uses the preload interposition logic (per Launchpad #2144723).

Changes:

  • Add a pthread_atfork() child handler to reset internal mutexes after fork().
  • Register the at-fork handler via a constructor (on_load) when the preload library is loaded.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@martinpitt
Copy link
Copy Markdown
Owner

Or else there's a risk the child process has inherited mutexes that
are already locked, resulting in a deadlock as soon as it tries to
use them.

https://bugs.launchpad.net/bugs/2144723
@vanvugt vanvugt force-pushed the fix-deadlock-after-fork branch from 44f1457 to ac78950 Compare March 20, 2026 05:41
Copy link
Copy Markdown
Owner

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I'll do a release now.

@martinpitt martinpitt merged commit 15ddf35 into martinpitt:main Mar 22, 2026
26 of 28 checks passed
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.

3 participants