Git Product home page Git Product logo

Comments (4)

sds avatar sds commented on July 20, 2024

Thanks for opening an issue @soapy1!

Digging into this a little further, what I can see is that we set the DETACHED_PROCESS flag passed to the CreateWindowsW function call.

The Win32 API documentation for the DETACHED_PROCESS flag suggests we are using it incorrectly. "Detach" in this context simply means the process isn't attached to the same console/terminal as the parent, whereas "detach" in the way ChildProcess uses it is more referring to the Process::detach helper.

I unfortunately do not have easy access to a Windows machine at this time, but I wonder if simply calling Process::detach in ChildProcess::Windows::ProcessBuilder.start would do the trick. Since you are running this on Windows, would you be able to apply the following diff and running locally to see if it fixes your issue? It may not, as Process::detach may be specific to Unix systems. Would happily accept a pull request if it works, however!

See lib/childprocess/windows/process_builder.rb

        def start
          create_command_pointer
          create_environment_pointer
          create_cwd_pointer

          setup_flags
          setup_io

          pid = create_process
+         Process.detach(pid) if @detach
          close_handles

          pid
        end

Appreciate your help!

from childprocess.

soapy1 avatar soapy1 commented on July 20, 2024

Thanks for digging into this!
I applied the patch and it looks like it returns an error.

C:\Users\vagrant\Desktop\test>ruby bug.rb
Parent process started
Traceback (most recent call last):
        5: from bug.rb:4:in `<main>'
        4: from bug.rb:20:in `<class:ProcessTest>'
        3: from bug.rb:14:in `start'
        2: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/childprocess-3.0.0/lib/childprocess/abstract_process.rb:81:in `start'
        1: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/childprocess-3.0.0/lib/childprocess/windows/process.rb:70:in `launch_process'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/childprocess-3.0.0/lib/childprocess/windows/process_builder.rb:35:in `start': undefined method `detach' for ChildProcess::Windows::Process:Class (NoMethodError)

I made a slight modification to ::Process.detach(pid) if @detach. This doesn't produce an error, however the problem persists.

from childprocess.

soapy1 avatar soapy1 commented on July 20, 2024

I dug into this a little more and I found that JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE is getting set. From the windows docs on managing jobs it looks like setting this flag will kill a child process when the parent terminates as part. Here is a little PR for not setting that flag if running in detached mode #167

from childprocess.

sds avatar sds commented on July 20, 2024

Thank you for digging into this and submitting a PR in #167. Closing as while we don't have any tests, I am assuming this solved the issue for you locally. Thanks again!

from childprocess.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.