From db3a6a9e8bcd76c311574dd91f5cb775e75eeb9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=AAnnis=20Dantas?= Date: Tue, 8 May 2018 00:18:20 -0300 Subject: [PATCH] fix(dbtest): Use os.Kill on windows instead of Interrupt :bug: I've added a use for os.Kill, instead of os.Interrupt signal, when using Windows. I'm current developing my project on Windows, and using DBServer.Stop() was resulting in: "timeout waiting for mongod process to die". After investigating, I've discovered that os.Interrupt isn't implemented on Windows, and it seems golang has Frozen this issue due to age (2013). They instruct to use os.Kill instead. Using this, the DBServer on my project works with no problem. --- dbtest/dbserver.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dbtest/dbserver.go b/dbtest/dbserver.go index 2fadaf764..3840827f9 100644 --- a/dbtest/dbserver.go +++ b/dbtest/dbserver.go @@ -6,6 +6,7 @@ import ( "net" "os" "os/exec" + "runtime" "strconv" "time" @@ -70,7 +71,7 @@ func (dbs *DBServer) start() { err = dbs.server.Start() if err != nil { // print error to facilitate troubleshooting as the panic will be caught in a panic handler - fmt.Fprintf(os.Stderr, "mongod failed to start: %v\n",err) + fmt.Fprintf(os.Stderr, "mongod failed to start: %v\n", err) panic(err) } dbs.tomb.Go(dbs.monitor) @@ -113,7 +114,12 @@ func (dbs *DBServer) Stop() { } if dbs.server != nil { dbs.tomb.Kill(nil) - dbs.server.Process.Signal(os.Interrupt) + // Windows doesn't support Interrupt + if runtime.GOOS == "windows" { + dbs.server.Process.Signal(os.Kill) + } else { + dbs.server.Process.Signal(os.Interrupt) + } select { case <-dbs.tomb.Dead(): case <-time.After(5 * time.Second):