#chan not receiving SIGTERM from external process handle

19 messages · Page 1 of 1 (latest)

peak gust
#

I have a go program that is launched from a JS application that keeps a handle on the go process. When I attempt to kill the process with SIGTERM, I never see in the go program's logs that the chan received the signal. Does go not receive signal from external processes? I would presume it does.

mossy thorn
#

Are you using os/signal?

peak gust
#

yup

mossy thorn
#

Can you show how you're handling the signal?

#

If you kill it manually do you see it?

peak gust
#

yup

#
sc = make(chan os.Signal)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM)
<-sc
conductShutdown()
...
func conductShutdown() {
  println("shutting down server")
  err := dbRunner.Shutdown()
  if err != nil { 
    println(fmt.Sprintf("failed to shutdown database: %s", err.Error()))
  }
}

JS

processHandle?.kill('SIGTERM')
#

And yes, when handling it any other way, it does work.

cursive star
#

wdmym by when handling it any other way ?
can you explain?

mossy thorn
#

I think you're not sending the signal

#

Is processhandle null?

mossy thorn
peak gust
#

Correct, I think the issue lies in SIGTERM, nodejs does not handle SIGTERM on windows but does SIGINT. So I swapped that out and it looks to be working now.

#

Also needed to change the make to make(chan os.Signal, 1)

#

Actually it still doesnt work lol

timber herald
#

while windows does use signals, it's not unix, there is no SIGTERM on windows. SIGINT should work tho

#

also don't use println, especially not println(fmt.Sprintf(...)) use fmt.Println or fmt.Printf

#

also note this excerpt from nodejs docs "Windows does not support signals so has no equivalent to termination by signal, but Node.js offers some emulation with process.kill(), and subprocess.kill():" https://nodejs.org/api/process.html. Either way this seems like a node question, not a go one so I'd try my luck with the node community.