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

Replace ChildProcess with Process.spawn #892

Merged
merged 13 commits into from
Feb 12, 2023

Conversation

mvz
Copy link
Contributor

@mvz mvz commented Jan 21, 2023

Summary

This replaces ChildProcess with Process.spawn for the purpose of starting, stopping and controlling the processes under test.

Details

To make this change be the least invasive, I created a new class that emulates the interface provided by ChildProcess, with a few differences where this was more practical. For example, where ChildProcess provides an #io method that returns an object giving access to stdout etc., this new class simply privides #stdout and related methods directly.

This also removes the childprocess dependency.

Motivation and Context

This fixes #884.

How Has This Been Tested?

I ran the full test suite with MRI 3.2 and JRuby 9.4.

I also added specs for SpawnProcess so its tested more fully in the RSpec suite.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Internal change (refactoring, test improvements, developer experience or update of dependencies)

Checklist:

  • I've added tests for my code

@olleolleolle
Copy link
Contributor

Many high-fives for this amazing piece!

@mvz mvz force-pushed the replace-childprocess-with-process-spawn branch from 0ba94f4 to ff6c4cf Compare January 21, 2023 10:20
@mvz mvz force-pushed the replace-childprocess-with-process-spawn branch 2 times, most recently from aac3658 to 1c9d78b Compare January 21, 2023 19:21
@olleolleolle
Copy link
Contributor

@mvz This is quite exciting - what could be the signal that triggers the EINVAL? Would you care to pair while finding out?

@olleolleolle
Copy link
Contributor

@mvz Around the signals: The Thin web server also skips handling HUP on Windows.

https://github.com/macournoyer/thin/blob/02f0a3a72620313c69a1d797671cc522399d9b4c/lib/thin/server.rb#L241

@mvz
Copy link
Contributor Author

mvz commented Jan 21, 2023

I made it log the signal and it's the TERM signal which I've currently mapped to signal 3 for Windows (I'm going to undo that mapping since just sending the signal name should work just fine).

However, now I found this explanation of how things work on Windows: enkessler/childprocess#114 (comment). So, I'm going to try that experiment with that now.

I unfortunately have no Windows machine available so debugging is via GitHub Actions.

I may have to skip the spec that tests HUP on Windows since the whole point is to send a custom signal, and Windows seems to only support KILL.

@mvz mvz force-pushed the replace-childprocess-with-process-spawn branch from 12d7af0 to d282def Compare January 21, 2023 21:11
Process.spawn takes care of the escaping for us.
On Windows, the TERM signal is not supported. Just skip it for now.
@mvz mvz force-pushed the replace-childprocess-with-process-spawn branch from d282def to 424c4f6 Compare January 21, 2023 21:33
@olleolleolle
Copy link
Contributor

olleolleolle commented Jan 22, 2023

@mvz Great job!

Also, interesting to learn from enkessler (well pevtsoff) here.

@mvz
Copy link
Contributor Author

mvz commented Jan 22, 2023

Thanks @olleolleolle. pevtsoff does not seem very active in the Ruby world at the moment. I've asked the submitter of #884 to comment, though.

@mvz mvz merged commit 1f1ad04 into main Feb 12, 2023
@mvz mvz deleted the replace-childprocess-with-process-spawn branch February 12, 2023 13:40
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.

Use Process.spawn instead of the child_process gem
2 participants