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

cmd/go: using go test, goroutine stack dump sometimes not emitted on SIGQUIT #27189

Open
mark-rushakoff opened this Issue Aug 24, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@mark-rushakoff
Contributor

mark-rushakoff commented Aug 24, 2018

What version of Go are you using (go version)?

Tried go version go1.10.3 darwin/amd64, go version go1.11rc1 darwin/amd64, and go version devel +6e76aeba0b Thu Aug 23 20:27:47 2018 +0000 darwin/amd64.

What did you do?

I had a test that appeared to be stuck in a blocking operation, and I pressed ^\ to send SIGQUIT, but I didn't receive any output. Then when I ran the test again using go test -v, sending SIGQUIT produced the goroutine stacks I expected to see.

Here's a sample test I'm using in the following output:

package main

import (
	"testing"
	"time"
)

func TestSleep(t *testing.T) {
	time.Sleep(time.Minute)
}

Running just go test . doesn't produce output on SIGQUIT, but I do see output with go test -v ..

$ /usr/local/Cellar/go/1.10.3/bin/go test .
^\
$ /usr/local/Cellar/go/1.10.3/bin/go test -v .
=== RUN   TestSleep
^\SIGQUIT: quit
PC=0x105508b m=0 sigcode=0

goroutine 0 [idle]:
...
FAIL	_/tmp/b	2.084s

$ gotip test .
^\
$  gotip test -v .
=== RUN   TestSleep
^\SIGQUIT: quit
PC=0x7fff706a6a1e m=0 sigcode=0

goroutine 0 [idle]:
...
FAIL	_/tmp/b	1.859s

If I change the file to include a test that calls t.Log, then I seem to be able to get a stack dump with tip, but not with 1.10 or 1.11rc1:

$ cat sleep_test.go
package main

import (
	"testing"
	"time"
)

func TestPass(t *testing.T) {
	t.Logf("ok")
}

func TestSleep(t *testing.T) {
	time.Sleep(time.Minute)
}

$ /usr/local/Cellar/go/1.10.3/bin/go test  .
^\
$ go test  .
^\
$ gotip test  .
^\SIGQUIT: quit
PC=0x7fff706a6a1e m=0 sigcode=0

goroutine 0 [idle]:
...
FAIL	_/tmp/b	6.311s

If I comment out the t.Logf call, but keep TestPass, then gotip no longer produces a stack dump on SIGQUIT.

@mark-rushakoff

This comment has been minimized.

Contributor

mark-rushakoff commented Aug 24, 2018

If I use go test -c to compile a test binary, than I seem to always get a stack dump on SIGQUIT, for 1.10, 1.11rc1, and tip.

@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Aug 24, 2018

@mark-rushakoff

This comment has been minimized.

Contributor

mark-rushakoff commented Sep 4, 2018

I don't fully understand what's going on here, but it seems related to the call to base.StartSigHandlers in cmd/go/internal/test/test.go:

base.StartSigHandlers()

which seems to swallow SIGQUIT:

// Interrupted is closed when the go command receives an interrupt signal.
var Interrupted = make(chan struct{})
// processSignals setups signal handler.
func processSignals() {
sig := make(chan os.Signal)
signal.Notify(sig, signalsToIgnore...)
go func() {
<-sig
close(Interrupted)
}()
}
var onceProcessSignals sync.Once
// StartSigHandlers starts the signal handlers.
func StartSigHandlers() {
onceProcessSignals.Do(processSignals)
}

var signalsToIgnore = []os.Signal{os.Interrupt, syscall.SIGQUIT}

@davecheney

This comment has been minimized.

Contributor

davecheney commented Sep 5, 2018

@bcmills

This comment has been minimized.

Member

bcmills commented Nov 15, 2018

If I change the file to include a test that calls t.Log, then I seem to be able to get a stack dump with tip, but not with 1.10 or 1.11rc1

Possibly related to #24929?

@bcmills bcmills modified the milestones: Go1.12, Go1.13 Nov 15, 2018

@bcmills bcmills added the GoCommand label Nov 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment