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

runtime/trace: Tracing error when catching SIGINT #57572

Open
jeremfrs opened this issue Jan 4, 2023 · 1 comment
Open

runtime/trace: Tracing error when catching SIGINT #57572

jeremfrs opened this issue Jan 4, 2023 · 1 comment
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@jeremfrs
Copy link

jeremfrs commented Jan 4, 2023

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

$ go version
go version go1.19.4 windows/amd64

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=auto
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\jeremies\AppData\Local\go-build
set GOENV=C:\Users\jeremies\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\jeremies\Documents\Perso\Trunk\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\jeremies\Documents\Perso\Trunk\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.19.4
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\jeremies\AppData\Local\Temp\go-build511942346=/tmp/go-build -gno-record-gcc-switches

What did you do?

I am trying to trace my golang program. Here is the code I used to produce the error

package main

import (
	"fmt"
	"os"
	"os/signal"
	"runtime/trace"
	"syscall"
)

func main() {
	f, err := os.Create("trace.out")
	if err != nil {
		panic(err)
	}
	defer f.Close()

	err = trace.Start(f)
	if err != nil {
		panic(err)
	}
	defer trace.Stop()

	// random stuff
	a := 0
	for i := 0; i < 10; i++ {
		a += i
	}
	fmt.Println(a)
	// end random stuff

	sigint := make(chan os.Signal, 1)
	signal.Notify(sigint, syscall.SIGINT)

	<-sigint // this creates the problem
}

Then I used the cmd/runtime tool but I get the following error :

$ go tool trace trace.out
2023/01/04 12:49:43 Parsing trace...
failed to parse trace: no consistent ordering of events possible

If I remove the signal catching part of the code, the tool works fine. Is this a normal behavior ? I find it weird that catching a sigint causes this. Is there a way to fix this ?

Thank you

EDIT: From what was tested, this problem only occurs on windows (i have tested it on windows 10 and 11). I also tried to use os.Interrupt, syscall.SIGTERM instead but it does not help.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jan 4, 2023
@mdempsky
Copy link
Member

mdempsky commented Jan 4, 2023

/cc @mknyszek

@heschi heschi added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 4, 2023
@heschi heschi added this to the Go1.21 milestone Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: Todo
Development

No branches or pull requests

5 participants