Skip to content

runtime: crash in GoroutineProfile #6946

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

Closed
rsc opened this issue Dec 13, 2013 · 5 comments
Closed

runtime: crash in GoroutineProfile #6946

rsc opened this issue Dec 13, 2013 · 5 comments

Comments

@rsc
Copy link
Contributor

rsc commented Dec 13, 2013

This program should run forever. It crashes quickly, because GoroutineProfile is using
the wrong pc/sp combination for the traceback if the corresponding goroutine has just
come out of a system call.

The only workaround is not to call GoroutineProfile. Possible #go121 candidate.

package main

import (
    "runtime"
    "syscall"
)

func main() {
    runtime.GOMAXPROCS(200)
    for i := 0; i < 10; i++ {
        go func() {
            for {
                syscall.Close(-1)
            }
        }()
    }
    stk := make([]runtime.StackRecord, 1000)
    for n := 0;; n++ {
        _, ok := runtime.GoroutineProfile(stk)
        if !ok {
            panic("GoroutineProfile refused")
        }
        if n&(n-1) == 0 {
            println(n)
        }
    }
}

panic: invalid memory address or nil pointer dereference
fatal error: panic during gc
[signal 0xb code=0x1 addr=0x0 pc=0x1a7f5]

goroutine 1 [running]:
runtime.throw(0x6b1ac)
    /Users/rsc/g/go/src/pkg/runtime/panic.c:462 +0x69 fp=0x2210248d40
runtime.panicstring(0x6b5b9)
    /Users/rsc/g/go/src/pkg/runtime/panic.c:477 +0x8d fp=0x2210248d68
runtime.sigpanic()
    /Users/rsc/g/go/src/pkg/runtime/os_darwin.c:450 +0x16a fp=0x2210248d80
runtime.gentraceback(0x7850, 0x0, 0x0, 0x2100d8ea0, 0x0, ...)
    /Users/rsc/g/go/src/pkg/runtime/traceback_x86.c:101 +0x745 fp=0x2210248e40
saveg(0x7850, 0x0, 0x2100d8ea0, 0x210148600)
    /Users/rsc/rscgo/src/pkg/runtime/mprof.goc:531 +0x76 fp=0x2210248ea0
runtime.GoroutineProfile(0x210148000, 0x3e8, 0x3e8, 0xc, 0x301)
    /Users/rsc/rscgo/src/pkg/runtime/mprof.goc:559 +0x148 fp=0x2210248ee8
main.main()
    /Users/rsc/x.go:19 +0xbd fp=0x2210248f48
runtime.main()
    /Users/rsc/g/go/src/pkg/runtime/proc.c:220 +0x11f fp=0x2210248fa0
runtime.goexit()
    /Users/rsc/g/go/src/pkg/runtime/proc.c:1394 fp=0x2210248fa8
@rsc
Copy link
Contributor Author

rsc commented Dec 13, 2013

Comment 1:

https://golang.org/cl/41640043

@ianlancetaylor
Copy link
Contributor

Comment 2:

This meets the criteria for 1.2.x release: a critical bug with no workaround.  The
#go121 tag in the text isn't sufficient, because we not only need a way to mark issues
as appropriate for 1.2.1, but we also need a way to remove that marking.  So I'm
changing the release tag to Release-Go1.2.1.

Labels changed: added release-go1.2.1, removed release-go1.3.

@rsc
Copy link
Contributor Author

rsc commented Dec 13, 2013

Comment 3:

This issue was closed by revision bc135f6.

Status changed to Fixed.

@rsc
Copy link
Contributor Author

rsc commented Feb 16, 2014

Comment 4:

Okay for 1.2.1.

@rsc
Copy link
Contributor Author

rsc commented Feb 28, 2014

Comment 5:

This issue was closed by revision 7ada9e760ce3.

@rsc rsc added fixed labels Feb 28, 2014
@rsc rsc self-assigned this Feb 28, 2014
@rsc rsc added this to the Go1.2.1 milestone Apr 14, 2015
rsc added a commit that referenced this issue May 11, 2015
This CL is not exactly a copy of the original quoted below.
This CL omits the changes made to mgc0.c in the original.
Those changes do not apply cleanly to the Go 1.2 tree,
and they were cosmetic, simplifying code that was already
doing the right thing.

To double-check that omitting the mgc0.c change has not
invalidated the fix, I have verified by hand that the test program
in issue 6946 fails without this CL and passes with this CL.

««« CL 41640043 / e4c381446b48
runtime: fix crash in runtime.GoroutineProfile

This is a possible Go 1.2.1 candidate.

Fixes #6946.

R=iant, r
CC=golang-dev
https://golang.org/cl/41640043
»»»

LGTM=adg
R=adg
CC=golang-codereviews, golang-dev, iant, r
https://golang.org/cl/68820045
@golang golang locked and limited conversation to collaborators Jun 25, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants