From 7b53663a226990b95cff7593654e4b109f05106d Mon Sep 17 00:00:00 2001 From: Prashant Varanasi Date: Tue, 7 Jan 2020 11:44:09 -0800 Subject: [PATCH] Ignore blocked trace stack by default (#40) When running tests with `-trace`, a background goroutine blocks on `runtime.ReadTrace`: ``` Goroutine 20 in state trace reader (blocked), with runtime.goparkunlock on top of the stack: goroutine 20 [trace reader (blocked)]: runtime.goparkunlock(...) (truncated)/go1.13.linux.amd64/src/runtime/proc.go:310 runtime.ReadTrace(0xc00008e048, 0xc0000160d0, 0x10) (truncated)/go1.13.linux.amd64/src/runtime/trace.go:395 +0x4ed runtime/trace.Start.func1(0x7b3dc0, 0xc00008e048) (truncated)/go1.13.linux.amd64/src/runtime/trace/trace.go:129 +0x47 created by runtime/trace.Start (truncated)/go1.13.linux.amd64/src/runtime/trace/trace.go:127 +0xd8 ``` Skip this stack by default. Run tests with `-trace` enabled to verify that this stack should be skipped. Fixes #39. --- Makefile | 1 + options.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/Makefile b/Makefile index d419e66..53763fa 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ install: .PHONY: test test: go test -v -race ./... + go test -v -trace=/dev/null . .PHONY: cover cover: diff --git a/options.go b/options.go index b1d7419..e011ba1 100644 --- a/options.go +++ b/options.go @@ -78,6 +78,7 @@ func buildOpts(options ...Option) *opts { isTestStack, isSyscallStack, isStdLibStack, + isTraceStack, ) for _, option := range options { option.apply(opts) @@ -141,3 +142,11 @@ func isStdLibStack(s stack.Stack) bool { // Using signal.Notify will start a runtime goroutine. return strings.Contains(s.Full(), "runtime.ensureSigM") } + +func isTraceStack(s stack.Stack) bool { + if f := s.FirstFunction(); f != "runtime.goparkunlock" { + return false + } + + return strings.Contains(s.Full(), "runtime.ReadTrace") +}