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

Terminating subprocess on Windows when "running" is flaky #41

Open
MaxmaxmaximusAWS opened this issue Apr 28, 2021 · 5 comments
Open

Terminating subprocess on Windows when "running" is flaky #41

MaxmaxmaximusAWS opened this issue Apr 28, 2021 · 5 comments
Labels
Windows Specific to Microsoft Windows

Comments

@MaxmaxmaximusAWS
Copy link

MaxmaxmaximusAWS commented Apr 28, 2021

"estrella": "^1.4.0",

This config:

estrella.build({
  watch: true,
  run: "node build/index.js" // this process not killing
})

Temporary solution:

let childProcess = null

estrella.build({
  onEnd: () => {
    if (childProcess) { 
      childProcess.kill('SIGINT')
    }

    childProcess = spawn('node', ['build/index.js'], {
      stdio: [process.stdin, process.stdout, process.stderr],
    })
  },
})
@rsms
Copy link
Owner

rsms commented May 12, 2021

What OS are you using?
(Estrella uses Nodejs's child_process module and process groups on POSIX systems to allow for process tree control)

@rsms
Copy link
Owner

rsms commented May 12, 2021

Also can you please provide a complete repro? (ideally as a gist or a zip or tar archive)

FTR, the signalling code is here:

estrella/src/exec.ts

Lines 272 to 320 in 7294055

// signal sends sig to the underlying process and returns true if sending the signal worked.
// mode defaults to "standard"
//
// If the signal is successfully sent (not neccessarily delivered) true is returned.
// If the process is not running, false is returned (no effect.)
// If the process has not been started, an exception is thrown.
// If the signal is not supported by the platform, an exception is thrown.
// If another error occur, like signalling permissions, false is returned.
//
signal(sig :Signal, mode? :SignalMode) :boolean {
const p = this._checkproc()
if (mode == "group") {
// Signalling process groups via negative pid is supported on most POSIX systems.
// This causes subprocesses that the command process may have started to also receive
// the signal.
try {
process.kill(-p.pid, sig)
return true
} catch (_) {
// will fail if the process is not in its own group or if its is already dead.
// fall through to "proc" mode:
}
}
return p.kill(sig)
}
// kill terminates the command by sending signal sig to the process and waiting for it to exit.
// mode defaults to "group".
//
// If the process has not exited within timeout milliseconds, SIGKILL is sent.
// The timeout should be reasonably large to allow well-behaved processed to run atexit code but
// small enough so that an ill-behaved process is killed within a reasonable timeframe.
// If timeout <= 0 then the returned promise will only resolve if and when the process exits,
// which could be never if the process ignores sig.
//
async kill(sig :Signal="SIGTERM", timeout :number=500, mode? :SignalMode) :Promise<number> {
const p = this._checkproc()
if (!this.signal(sig, mode || "group")) {
return p.exitCode || 0
}
if (timeout <= 0) {
return this.promise
}
return this._waitTimeout(timeout, (_, resolve) => {
log.debug(()=>`${this} kill timeout reached; sending SIGKILL`)
p.kill("SIGKILL")
return this.promise.then(resolve)
})
}

@rsms rsms added the question Further information is requested label May 12, 2021
@MaxmaxmaximusAWS
Copy link
Author

What OS are you using?
(Estrella uses Nodejs's child_process module and process groups on POSIX systems to allow for process tree control)

windows 10 of course

@rsms
Copy link
Owner

rsms commented May 13, 2021

Ah, yeah you're going to have some issues if the process is not responding to hangup or int signals.
You could try WSL or run your build manually (either in a BAT script or from js in onEnd, but you'll likely run into similar issues as with estrella using nodejs.)

@rsms rsms added Windows Specific to Microsoft Windows and removed question Further information is requested labels May 13, 2021
@rsms rsms changed the title Old process not killing when hot reloading Terminating subprocess on Windows when "running" is flaky May 13, 2021
@MaxmaxmaximusAWS
Copy link
Author

MaxmaxmaximusAWS commented May 13, 2021

Why you not use this code in windows platforms? =) This fix works on me:

let childProcess = null

estrella.build({
  onEnd: () => {
    if (childProcess) { 
      childProcess.kill('SIGINT')
    }

    childProcess = spawn('node', ['build/index.js'], {
      stdio: [process.stdin, process.stdout, process.stderr],
    })
  },
})

i can use WSL or WSL2 or docker or my macbook, but we need fix the bug, not hide the bug)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Windows Specific to Microsoft Windows
Projects
None yet
Development

No branches or pull requests

2 participants