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

Process.currentDirectoryURL affects global state on Linux #59610

Closed
Lukasa opened this issue Jun 21, 2022 · 0 comments · Fixed by swiftlang/swift-corelibs-foundation#4606
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@Lukasa
Copy link
Contributor

Lukasa commented Jun 21, 2022

Describe the bug

Process.currentDirectoryURL is implemented on top of chdir in swift-corelibs-foundation. As a result, using multiple, unrelated Process objects from multiple threads in Linux that have this property set can cause wildly unexpected outcomes, leaving the working directory of the current process and all child processes set essentially randomly.

To Reproduce
Steps to reproduce the behavior:

  1. Call Process from multiple threads at once with different currentDirectoryURL values
    ...

Expected behavior
All child processes execute in the expected directory and the parent working directory is unchanged

@Lukasa Lukasa added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Jun 21, 2022
MaxDesiatov pushed a commit to swiftlang/swift-corelibs-foundation that referenced this issue Jun 14, 2023
We allow users to set the working directory of the child process when they use the Process API. Unfortunately, this was implemented by calling chdir in the parent process, which has nasty global effects on the process and cannot safely be used concurrently.

glibc has a non-POSIX extension to posix_spawn that can call chdir in the child process, so we add that call instead where it's available, and add a regression test.

Resolves swiftlang/swift#59610.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant