Skip to content

Missing GIL release and mutable state race in HeightErrorFunction#1287

Open
cstollmeta wants to merge 1 commit intomainfrom
export-D100865760
Open

Missing GIL release and mutable state race in HeightErrorFunction#1287
cstollmeta wants to merge 1 commit intomainfrom
export-D100865760

Conversation

@cstollmeta
Copy link
Copy Markdown
Contributor

Summary:
This diff fixes two thread-safety bugs:

  1. Solver.solve() in pymomentum did not release the Python GIL during CPU-intensive Gauss-Newton optimization, blocking all Python threads. Added py::gil_scoped_release matching the pattern already used in solve_sequence().

  2. HeightErrorFunctionT stored mutable SkeletonStateT and MeshStateT as class members. When the same error function instance was shared across frames via addErrorFunction(kAllFrames, ...), the sequence solver's parallel frame processing would concurrently mutate these members, causing a data race. Fixed by converting mutable members to local variables in each method and passing them as parameters to helper functions. This makes HeightErrorFunctionT stateless and safe for shared use across parallel frames.

Differential Revision: D100865760

Summary:
This diff fixes two thread-safety bugs:

1. Solver.solve() in pymomentum did not release the Python GIL during CPU-intensive Gauss-Newton optimization, blocking all Python threads. Added py::gil_scoped_release matching the pattern already used in solve_sequence().

2. HeightErrorFunctionT stored mutable SkeletonStateT and MeshStateT as class members. When the same error function instance was shared across frames via addErrorFunction(kAllFrames, ...), the sequence solver's parallel frame processing would concurrently mutate these members, causing a data race. Fixed by converting mutable members to local variables in each method and passing them as parameters to helper functions. This makes HeightErrorFunctionT stateless and safe for shared use across parallel frames.

Differential Revision: D100865760
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 15, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented Apr 15, 2026

@cstollmeta has exported this pull request. If you are a Meta employee, you can view the originating Diff in D100865760.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant