Fix fork+threading deadlock in SWE-Bench image builds#486
Draft
juanmichelini wants to merge 1 commit intomainfrom
Draft
Fix fork+threading deadlock in SWE-Bench image builds#486juanmichelini wants to merge 1 commit intomainfrom
juanmichelini wants to merge 1 commit intomainfrom
Conversation
Root cause: Commit 2bfcc6c added 'from openhands.sdk import get_logger' to image_utils.py, which auto-initializes RichHandler with locks/threads. When build_utils.py uses ProcessPoolExecutor with fork (default on Linux), it copies the process with Rich logger's locks in their current state, causing child processes to deadlock waiting for locks that will never be released. Solution: Use 'spawn' multiprocessing context instead of 'fork' in build_all_images(), matching the fix in commit 744df22 for evaluation.py. This prevents the fork+threading deadlock by starting fresh Python processes instead of forking processes with inherited thread state. Fixes #476 Co-authored-by: openhands <openhands@all-hands.dev>
5 tasks
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.
Summary
This PR fixes the root cause of issue #476 where SWE-Bench image builds get stuck for 5+ hours during the batch build process.
Root Cause
Commit
2bfcc6c(#456) introduced the following import inbenchmarks/utils/image_utils.py:When this module is imported, the SDK logger auto-initializes with a
RichHandler(from therichlibrary), which uses locks and potentially threads for console rendering. The issue occurs when:build_utils.pyimportsimage_utils, triggering logger initialization in the parent processbuild_all_images()creates aProcessPoolExecutorusing fork (default on Linux)This is the exact same fork+threading deadlock that commit
744df225(#459) fixed inevaluation.py, but that fix only applied toevaluation.pyand not tobuild_utils.py.Evidence
From commit
744df225(#459):The same pattern applies to image building:
Solution
Use
spawnmultiprocessing context instead offorkinbuild_all_images(), matching the fix from commit744df225forevaluation.py.The spawn method starts fresh Python processes instead of forking, avoiding the fork+threads deadlock entirely.
Changes
import multiprocessingtobuild_utils.pyProcessPoolExecutorinstantiation to usemp_context=multiprocessing.get_context("spawn")evaluation.pyTesting
✅ All pre-commit checks pass
✅ Type checking passes
✅ Linting passes
The fix should be verified by running a full 500-image build on GitHub Actions, which was previously getting stuck.
Related
744df225(Fix fork+threading deadlock by switching to spawn multiprocessing #459)