Skip to content

(SPIKE)(MODULES-4754) Incomplete hard teardown of powershell.exe #178

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

Conversation

Iristyle
Copy link
Contributor

This is totally incomplete and possibly worth abandoning depending on if MODULES-4754 can be easily repro'd.

The idea here would be to more forcefully guarantee a PowerShell process should be terminated.... but it would use Windows APIs and therefore only work on Windows.

 - An idea here would be to use Windows APIs to inject a remote thread
   into powershell.exe, asking for it to exit cleanly... INSTEAD of the
   current approach of closing pipes from Ruby and hoping PowerShell
   exits properly.

   This approach would be a lot more forceful and has the downside of
   re-introducing FFI'd platform specific code that runs only on
   Windows.  There had been some effort up to this point to remove all
   such code to make this module more easily support cross-platform.
@@ -46,6 +188,7 @@ def initialize(cmd, debug)
ps_args = ['-File', self.class.init_path, "\"#{named_pipe_name}\""]
ps_args << '"-EmitDebugOutput"' if debug
# @stderr should never be written to as PowerShell host redirects output
# TODO: take a fd and turn it into a handle
stdin, @stdout, @stderr, @ps_process = Open3.popen3("#{cmd} #{ps_args.join(' ')}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better way to do this on Windows would be to start powershell.exe through Process.create which is monkey-patched by win32-process gem, allowing immediate access to the real handle.

However, that puts the module back into the mode of supporting multiple OSes differently, which is less than ideal. (popen3 uses Rubys Process.spawn under the hood)

@Iristyle
Copy link
Contributor Author

Related to #177

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.

1 participant