Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSCBasic: fix race condition causing close errors #456

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Bo98
Copy link

@Bo98 Bo98 commented Dec 24, 2023

When compiling SwiftPM (via swift-bootstrap), I was very consistently getting a "close error" that would break the compile.

This appears to be a race condition as it only happens with overlapping popen calls, likely from the subprocess in the 2nd popen call inheriting all the pipe file descriptors from the previous popen call.

What seemed to fix it for me is instead of manually closing all pipes in the subprocess, we instead set O_CLOEXEC on the pipe - this will apply to all subprocesses so concurrent popen calls are no longer a concern.

It appears this issue may have popped up before but wasn't tracked down fully: #143 (indeed stdin seemed to be the one that would always error for me), #439 and friends.

Likely fixes #344.

This issue also affects both release branches, so could also be cherry picked there (I tested 5.9 and it fixes the issue there).

@neonichu
Copy link
Contributor

neonichu commented Jan 2, 2024

#439 was caused by a miscompile, but #143 may indeed be related.

@neonichu
Copy link
Contributor

neonichu commented Jan 2, 2024

@swift-ci please test

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.

pipe handling of Process::launch seems to be wrong
2 participants