-
Notifications
You must be signed in to change notification settings - Fork 79
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
Replace all backends by Process.spawn for portability, reliability and simplicity #175
Conversation
d1de572
to
58f8cf3
Compare
TravisCI passes, except on JRuby: https://travis-ci.org/github/enkessler/childprocess/builds/759130946 |
TravisCI now passes with the latest JRuby, as good as master + actually it also works on ruby-head: |
7ed0882
to
9c3a951
Compare
974a16a
to
22a811b
Compare
This is almost ready now. Windows has only 2 failures:
The first one might be some issue with JRuby on Linux & macOS has only 1 failure:
Which is most likely a bug of JRuby (since that works fine on CRuby). JRuby on Windows doesn't seem to work well, due to another JRuby bug, |
Ruby version 3.1 causes failures on Windows. This appears to be caused by the `childprocess` gem, and the way it launches executables. The error shows up when the Cucumber/Aruba library using `childprocess` to launch a program. `childprocess` is throwing an exception when it attempts to get a OS file handle for the file that output should be redirected to. The function call is returning -1, but the Windows "last error" isn't being set. This causes `childprocess` to generate an exception message that reads, "Windows says that the process completed successfully, but it did not". The process that is being referred to is the attempt to obtain the file handle for the file that should be used for streaming output. It is a little confusing, because at first glance, it seems like it might be referring to the process that should be launched. There is an open pull request (enkessler/childprocess#175) and corresponding issue that might resolve the issue (enkessler/childprocess#172). For now, running on 3.0 seems like a decent enough work-around. An issue describing this problem, with detailed steps to repeat it, will be created in the `childprocess` GitHub project. It will also be brought to the attention of the Cucumber/Aruba project that is using the `childprocess` library.
16ddc23
to
f7471c8
Compare
Update: CI is green on Linux and macOS. On Windows there is a single failure:
Note that keeping the original code does not solve this.
Maybe https://stackoverflow.com/a/61113184/388803 is an option. JRuby on Windows is so broken it can't even load rspec, so I ignore that for now. I gave it a try to keep the existing logic for JRuby and Windows backends, but that seems to only results in more test failures, so I don't see the point: https://github.com/eregon/childprocess/tree/process-spawn-non-windows https://github.com/eregon/childprocess/actions/runs/4235173639 |
Given the latest release is 4.1.0, I think this change would deserve its own major version, i.e. 5.0.0. |
Thank you so much on your work on this! :) I don't how many are out there, but I like the interfaces provided by this gem, and depend on it for my private tooling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your effort, @eregon. Sorry for the delay in response.
Can we rebase this PR and remove the JRuby/Windows tests that we can't get working? Would rather have a working CI build for macOS/Linux and just cut a new major version with a heads up to folks that support for these other OSes & Ruby runtimes may not be complete.
Thank you!
This would also solve issues like #186? With this branch, I was able to use |
I found a difference between this PR and the latest release: keys in the environment hash now needs to be strings From root@14303433afe8:/app# cat minimal_repro.rb
require "bundler/inline"
gemfile do
if ENV.key?("PR")
gem "childprocess", github: "https://github.com/enkessler/childprocess/pull/175"
else
source "https://rubygems.org"
gem "childprocess"
gem "ffi" if ENV.key?("CHILDPROCESS_POSIX_SPAWN")
end
end
process = ChildProcess.build("ruby", "--help")
process.environment.merge!({ FOO: "123" })
process.start
root@14303433afe8:/app# ruby minimal_repro.rb
root@14303433afe8:/app# PR=1 ruby minimal_repro.rb
/usr/local/bundle/bundler/gems/childprocess-f7471c8a90c1/lib/childprocess/process_spawn_process.rb:73:in `spawn': no implicit conversion of Symbol into String (TypeError)
@pid = ::Process.spawn(@environment, *args, options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
from /usr/local/bundle/bundler/gems/childprocess-f7471c8a90c1/lib/childprocess/process_spawn_process.rb:73:in `launch_process'
from /usr/local/bundle/bundler/gems/childprocess-f7471c8a90c1/lib/childprocess/abstract_process.rb:81:in `start'
from minimal_repro.rb:14:in `<main>' |
Actually, that might not be a difference between this PR and the latest release. It is just that this PR is the only way for me to use |
db3769e
to
228ec6d
Compare
It doesn't blow up, but childprocess 4.1.0 has a similar problem with |
Not a concern for this PR, as it removes all usage of |
This is ready now, the CI tests every Ruby from 2.4 (the required_ruby_version) to 3.3 as well as jruby and truffleruby. JRuby on Windows fails to load rspec, which is fully independent from this gem so I excluded that. I managed to fix the kill process tree feature on Windows by using |
That's because
It's the typical problem of having many backends, they get out of sync. This PR does the environment coercion correctly for all platforms. |
17ee66b
to
50f3aad
Compare
* Process.spawn requires only very minimal variants between platforms. * Remove all other backends, Process.spawn is enough.
* Inspired by https://stackoverflow.com/a/61113184/388803 * Using a subprocess for that is a bit heavy, OTOH we are already creating subprocess in ChildProcess and it only happens for a leader process on Windows. * There seems to be no other alternative which works reliably or it would incur huge complexity.
Use the awesome pull request by eregon: enkessler/childprocess#175 that uses native Process.spawn on all platforms JVM rubies can't use the default fork+exec approach in childprocess, so we fall back to CHILDPROCESS_POSIX_SPAWN, but that is not available on aarch64 (me using Docker on Apple silicon). Annoying when debugging tests. (This should still work even after the PR is merged and the branch removed)
Use the awesome pull request by eregon: enkessler/childprocess#175 that uses native Process.spawn on all platforms JVM rubies can't use the default fork+exec approach in childprocess, so we fall back to CHILDPROCESS_POSIX_SPAWN, but that is not available on aarch64 (me using Docker on Apple silicon). Annoying when debugging tests. (This should still work even after the PR is merged and the branch removed)
This commit pins the `childprocess` gem to version `4` since version `5.0.0` of enkessler/childprocess#175 seems to have broken JRuby support for spawning. Closes #15757 Co-authored-by: Andrea Selva <selva.andre@gmail.com> Co-authored-by: João Duarte <jsvd@users.noreply.github.com>
This commit pins the `childprocess` gem to version `4` since version `5.0.0` of enkessler/childprocess#175 seems to have broken JRuby support for spawning. Closes #15757 Co-authored-by: Andrea Selva <selva.andre@gmail.com> Co-authored-by: João Duarte <jsvd@users.noreply.github.com> (cherry picked from commit 9f1d55c)
This commit pins the `childprocess` gem to version `4` since version `5.0.0` of enkessler/childprocess#175 seems to have broken JRuby support for spawning. Closes #15757 Co-authored-by: Andrea Selva <selva.andre@gmail.com> Co-authored-by: João Duarte <jsvd@users.noreply.github.com> (cherry picked from commit 9f1d55c)
This commit pins the `childprocess` gem to version `4` since version `5.0.0` of enkessler/childprocess#175 seems to have broken JRuby support for spawning. Closes #15757 Co-authored-by: Andrea Selva <selva.andre@gmail.com> Co-authored-by: João Duarte <jsvd@users.noreply.github.com> (cherry picked from commit 9f1d55c)
This commit pins the `childprocess` gem to version `4` since version `5.0.0` of enkessler/childprocess#175 seems to have broken JRuby support for spawning. Closes #15757 Co-authored-by: Andrea Selva <selva.andre@gmail.com> Co-authored-by: João Duarte <jsvd@users.noreply.github.com> (cherry picked from commit 9f1d55c) Co-authored-by: Dimitrios Liappis <dimitrios.liappis@gmail.com>
This commit pins the `childprocess` gem to version `4` since version `5.0.0` of enkessler/childprocess#175 seems to have broken JRuby support for spawning. Closes #15757 Co-authored-by: Andrea Selva <selva.andre@gmail.com> Co-authored-by: João Duarte <jsvd@users.noreply.github.com> (cherry picked from commit 9f1d55c) Co-authored-by: Dimitrios Liappis <dimitrios.liappis@gmail.com>
This commit pins the `childprocess` gem to version `4` since version `5.0.0` of enkessler/childprocess#175 seems to have broken JRuby support for spawning. Closes #15757 Co-authored-by: Andrea Selva <selva.andre@gmail.com> Co-authored-by: João Duarte <jsvd@users.noreply.github.com> (cherry picked from commit 9f1d55c) Co-authored-by: Dimitrios Liappis <dimitrios.liappis@gmail.com>
From #172