build_environment.py: Prevent deadlock on install process join#51429
Merged
scheibelp merged 3 commits intospack:developfrom Oct 10, 2025
Merged
build_environment.py: Prevent deadlock on install process join#51429scheibelp merged 3 commits intospack:developfrom
scheibelp merged 3 commits intospack:developfrom
Conversation
Signed-off-by: John Parent <[email protected]>
Signed-off-by: John Parent <[email protected]>
scheibelp
reviewed
Oct 10, 2025
Signed-off-by: John Parent <[email protected]>
scheibelp
reviewed
Oct 10, 2025
scheibelp
approved these changes
Oct 10, 2025
Member
|
@scheibelp please label for backports next time :) |
3 tasks
3 tasks
Closed
becker33
pushed a commit
that referenced
this pull request
Jan 10, 2026
Currently in build_environment.complete_build_process we call join on the child installer process before we call recv on the write pipe. This can lead to a deadlock if the child is blocking on the send call to the write pipe. Per the python docs, Communication.send does not claim to block. For the implementation on Windows, it turns out it can if the pipe becomes filled. The issue is fixed by reading from the pipe in the parent process before joining the child process. --------- Signed-off-by: John Parent <[email protected]>
Merged
vjranagit
pushed a commit
to vjranagit/spack
that referenced
this pull request
Jan 18, 2026
…#51429) Currently in build_environment.complete_build_process we call join on the child installer process before we call recv on the write pipe. This can lead to a deadlock if the child is blocking on the send call to the write pipe. Per the python docs, Communication.send does not claim to block. For the implementation on Windows, it turns out it can if the pipe becomes filled. The issue is fixed by reading from the pipe in the parent process before joining the child process. --------- Signed-off-by: John Parent <[email protected]>
becker33
pushed a commit
that referenced
this pull request
Feb 2, 2026
Currently in build_environment.complete_build_process we call join on the child installer process before we call recv on the write pipe. This can lead to a deadlock if the child is blocking on the send call to the write pipe. Per the python docs, Communication.send does not claim to block. For the implementation on Windows, it turns out it can if the pipe becomes filled. The issue is fixed by reading from the pipe in the parent process before joining the child process. --------- Signed-off-by: John Parent <[email protected]>
becker33
pushed a commit
that referenced
this pull request
Feb 2, 2026
Currently in build_environment.complete_build_process we call join on the child installer process before we call recv on the write pipe. This can lead to a deadlock if the child is blocking on the send call to the write pipe. Per the python docs, Communication.send does not claim to block. For the implementation on Windows, it turns out it can if the pipe becomes filled. The issue is fixed by reading from the pipe in the parent process before joining the child process. --------- Signed-off-by: John Parent <[email protected]> Signed-off-by: Gregory Becker <[email protected]>
becker33
pushed a commit
that referenced
this pull request
Feb 19, 2026
Currently in build_environment.complete_build_process we call join on the child installer process before we call recv on the write pipe. This can lead to a deadlock if the child is blocking on the send call to the write pipe. Per the python docs, Communication.send does not claim to block. For the implementation on Windows, it turns out it can if the pipe becomes filled. The issue is fixed by reading from the pipe in the parent process before joining the child process. --------- Signed-off-by: John Parent <[email protected]> Signed-off-by: Gregory Becker <[email protected]>
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.
Currently in
build_environment.complete_build_processwe calljoinon the child installer process before we callrecvon the write pipe.This can lead to a deadlock if the child is blocking on the send call to the write pipe.
Per the python docs,
Communication.senddoes not claim to block, however, if you dig into the implementation ofsendon Windows, it uses_winapi.WriteFile(self._handle, buf, overlapped=True)under the hood, which, with anOVERLAPPED(async) handle and an anonymous pipe, will return false if the pipe buffer is full, per the win32 docs:The
sendmethod then callswaitres = _winapi.WaitForMultipleObjects([ov.event], False, INFINITE)which hangs infinitely until the child process is killed or the parent process frees up buffer space with a read.So if Spack's child installer process fills up that buffer with a send, it will hang on that send until the buffer is emptied, but if the parent process is waiting on a join to perform that read, Spack will deadlock and hang.
We are observing this with VTK and Paraview in CI (as can be observed here: https://gitlab.spack.io/spack/spack-packages/-/jobs/18409638, which is costing us approx 18 hours of CI time for each of these failures.
In these instances, Spack is sending 12kb into the pipe buffer, which exceeds the default buffer size of 8kb, leading to a deadlock.
Just moving the
recvcall to before the join empties the buffer, and ensures we can gracefully join the child.