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/pprof: panic during preempt: runtime error: index out of range #14046

Closed
kennylevinsen opened this issue Jan 20, 2016 · 3 comments
Closed

Comments

@kennylevinsen
Copy link

Steps to reproduce:

(port and hostname is obviously unimportant, but TLS is required)

Environment:

  • OS: OS X El Capitan
  • Revision: 36f959cc11809b5627ba5e0813dad3ba9a299fd4

Server that reproduces the issue (requires a cert.pem and key.pem file):

package main

import (
    "fmt"
    "log"
    "net/http"
    _ "net/http/pprof"
)

func main() {
    http.HandleFunc("/payload", func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprint(w, "1234")
    })
    http.HandleFunc("/script", func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprint(w, "while (true) { var x = new XMLHttpRequest(); x.open('get', '/payload'); x.send();}")
    })
    http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprint(w, "<html><head><script src='/script'></script></head><body></body></html>")
    })

    log.Fatal(http.ListenAndServeTLS(":8081", "cert.pem", "key.pem", nil))
}

Trace:

panic: runtime error: index out of range
preempt off reason: profile
fatal error: panic during preemptoff

goroutine 48 [running]:
runtime.throw(0x478f20, 0x17)
    /usr/local/Cellar/go/HEAD/libexec/src/runtime/panic.go:530 +0x90 fp=0xc82022b6f8 sp=0xc82022b6e0
runtime.gopanic(0x3adb60, 0xc82000a0b0)
    /usr/local/Cellar/go/HEAD/libexec/src/runtime/panic.go:382 +0x2c2 fp=0xc82022b778 sp=0xc82022b6f8
runtime.panicindex()
    /usr/local/Cellar/go/HEAD/libexec/src/runtime/panic.go:15 +0x49 fp=0xc82022b7a0 sp=0xc82022b778
runtime.GoroutineProfile(0xc820213000, 0xf, 0xf, 0x5, 0x1)
    /usr/local/Cellar/go/HEAD/libexec/src/runtime/mprof.go:545 +0x28e fp=0xc82022b850 sp=0xc82022b7a0
runtime/pprof.writeRuntimeProfile(0xfc1ab8, 0xc820116008, 0x1, 0x437dd0, 0x9, 0x4ddc08, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/runtime/pprof/pprof.go:545 +0xb8 fp=0xc82022b8d0 sp=0xc82022b850
runtime/pprof.writeGoroutine(0xfc1ab8, 0xc820116008, 0x1, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/runtime/pprof/pprof.go:507 +0x93 fp=0xc82022b918 sp=0xc82022b8d0
runtime/pprof.(*Profile).WriteTo(0x62a520, 0xfc1ab8, 0xc820116008, 0x1, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/runtime/pprof/pprof.go:236 +0xd4 fp=0xc82022ba38 sp=0xc82022b918
net/http/pprof.handler.ServeHTTP(0xc82011802d, 0x9, 0xfc1a58, 0xc820116008, 0xc82010a1c0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/pprof/pprof.go:210 +0x37e fp=0xc82022bb00 sp=0xc82022ba38
net/http/pprof.Index(0xfc1a58, 0xc820116008, 0xc82010a1c0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/pprof/pprof.go:222 +0x200 fp=0xc82022bc58 sp=0xc82022bb00
net/http.HandlerFunc.ServeHTTP(0x4ddaf0, 0xfc1a58, 0xc820116008, 0xc82010a1c0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/server.go:1616 +0x3a fp=0xc82022bc78 sp=0xc82022bc58
net/http.(*ServeMux).ServeHTTP(0xc820014ae0, 0xfc1a58, 0xc820116008, 0xc82010a1c0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/server.go:1908 +0x17d fp=0xc82022bcd0 sp=0xc82022bc78
net/http.serverHandler.ServeHTTP(0xc82006e180, 0xfc1a58, 0xc820116008, 0xc82010a1c0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/server.go:2079 +0x19e fp=0xc82022bd30 sp=0xc82022bcd0
net/http.initNPNRequest.ServeHTTP(0xc820174300, 0xc82006e180, 0xfc1a58, 0xc820116008, 0xc82010a1c0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/server.go:2485 +0x221 fp=0xc82022bec0 sp=0xc82022bd30
net/http.(*initNPNRequest).ServeHTTP(0xc82000b1f0, 0xfc1a58, 0xc820116008, 0xc82010a1c0)
    <autogenerated>:253 +0xb6 fp=0xc82022bef8 sp=0xc82022bec0
net/http.(Handler).ServeHTTP-fm(0xfc1a58, 0xc820116008, 0xc82010a1c0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/h2_bundle.go:3628 +0x50 fp=0xc82022bf30 sp=0xc82022bef8
net/http.(*http2serverConn).runHandler(0xc820088280, 0xc820116008, 0xc82010a1c0, 0xc820118040)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/h2_bundle.go:3841 +0x9f fp=0xc82022bf80 sp=0xc82022bf30
runtime.goexit()
    /usr/local/Cellar/go/HEAD/libexec/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc82022bf88 sp=0xc82022bf80
created by net/http.(*http2serverConn).processHeaderBlockFragment
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/h2_bundle.go:3634 +0x55e

goroutine 1 [IO wait]:
net.runtime_pollWait(0xf457f8, 0x72, 0xf40050)
    /usr/local/Cellar/go/HEAD/libexec/src/runtime/netpoll.go:160 +0x60
net.(*pollDesc).Wait(0xc8201326f0, 0x72, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/fd_poll_runtime.go:73 +0x3a
net.(*pollDesc).WaitRead(0xc8201326f0, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/fd_poll_runtime.go:78 +0x36
net.(*netFD).accept(0xc820132690, 0x0, 0xf45928, 0xc82017a0e0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/fd_unix.go:426 +0x27c
net.(*TCPListener).AcceptTCP(0xc82002e060, 0x12442, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/tcpsock_posix.go:254 +0x4d
net/http.tcpKeepAliveListener.Accept(0xc82002e060, 0x0, 0x0, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/server.go:2423 +0x41
crypto/tls.(*listener).Accept(0xc82013f180, 0x0, 0x0, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/crypto/tls/tls.go:52 +0x60
net/http.(*Server).Serve(0xc82006e180, 0xf458f0, 0xc82013f180, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/server.go:2115 +0x129
net/http.(*Server).ListenAndServeTLS(0xc82006e180, 0x42fcf0, 0xf, 0x42fd00, 0xe, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/server.go:2274 +0x38e
net/http.ListenAndServeTLS(0x426270, 0x5, 0x42fcf0, 0xf, 0x42fd00, 0xe, 0x0, 0x0, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/server.go:2226 +0xcd
main.main()
    /Users/kenny/dev/golang/src/github.com/joushou/test/main.go:21 +0xdd

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    /usr/local/Cellar/go/HEAD/libexec/src/runtime/asm_amd64.s:1998 +0x1

goroutine 19 [select]:
net/http.(*http2serverConn).serve(0xc820088280)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/h2_bundle.go:2944 +0xedc
net/http.(*http2Server).handleConn(0xc8200ba880, 0xc82006e180, 0xf459b0, 0xc820174300, 0xf84328, 0xc82000b1f0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/h2_bundle.go:2530 +0x986
net/http.http2ConfigureServer.func1(0xc82006e180, 0xc820174300, 0xf84328, 0xc82000b1f0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/h2_bundle.go:2467 +0x97
net/http.(*conn).serve(0xc820176180)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/server.go:1412 +0x777
created by net/http.(*Server).Serve
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/server.go:2135 +0x44e

goroutine 10 [IO wait]:
net.runtime_pollWait(0xf45678, 0x72, 0xc82017e800)
    /usr/local/Cellar/go/HEAD/libexec/src/runtime/netpoll.go:160 +0x60
net.(*pollDesc).Wait(0xc82016e0d0, 0x72, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/fd_poll_runtime.go:73 +0x3a
net.(*pollDesc).WaitRead(0xc82016e0d0, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/fd_poll_runtime.go:78 +0x36
net.(*netFD).Read(0xc82016e070, 0xc82017e800, 0x400, 0x400, 0x0, 0xf40050, 0xc82000a058)
    /usr/local/Cellar/go/HEAD/libexec/src/net/fd_unix.go:250 +0x23a
net.(*conn).Read(0xc820172008, 0xc82017e800, 0x400, 0x400, 0x0, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/net.go:172 +0xe4
crypto/tls.(*block).readFromUntil(0xc820170180, 0xf45a60, 0xc820172008, 0x5, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/crypto/tls/conn.go:460 +0xcc
crypto/tls.(*Conn).readRecord(0xc820174300, 0x4ddf17, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/crypto/tls/conn.go:562 +0x2d1
crypto/tls.(*Conn).Read(0xc820174300, 0xc8200bf008, 0x9, 0x9, 0x0, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/crypto/tls/conn.go:939 +0x167
io.ReadAtLeast(0xf843c8, 0xc820174300, 0xc8200bf008, 0x9, 0x9, 0x9, 0x0, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/io/io.go:297 +0xe6
io.ReadFull(0xf843c8, 0xc820174300, 0xc8200bf008, 0x9, 0x9, 0xc8204b5f00, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/io/io.go:315 +0x62
net/http.http2readFrameHeader(0xc8200bf008, 0x9, 0x9, 0xf843c8, 0xc820174300, 0x0, 0x0, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/h2_bundle.go:715 +0xa5
net/http.(*http2Framer).ReadFrame(0xc8200befd0, 0x0, 0x0, 0x0, 0x0)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/h2_bundle.go:906 +0xe9
net/http.(*http2serverConn).readFrames(0xc820088280)
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/h2_bundle.go:2848 +0x5a
created by net/http.(*http2serverConn).serve
    /usr/local/Cellar/go/HEAD/libexec/src/net/http/h2_bundle.go:2938 +0x720
@bradfitz bradfitz added this to the Go1.6Maybe milestone Jan 20, 2016
@bradfitz
Copy link
Contributor

Assigning to @aclements to de-dup or track.

@aclements
Copy link
Member

Looks like this was caused by @rsc's change to NumGoroutine in fac8202. GoroutineProfile checks that the caller passed in enough room for NumGoroutine() stacks and then iterates over allgs to collect stacks, but since NumGoroutine() now omits system goroutines, it will return less than the number of Gs in allgs. If the slice passed in by the caller is big enough for non-system goroutines, but too small for all goroutines, GoroutineProfile will panic.

@aclements aclements assigned rsc and unassigned aclements Jan 21, 2016
@aclements
Copy link
Member

(Moved to @rsc, but you can kick it back to me.)

gopherbot pushed a commit that referenced this issue Jan 27, 2016
The previous CL is the real fix. This one is just insurance.

Fixes #14046 again.

Change-Id: I553349504bb1789e4b66c888dbe4034568918ad6
Reviewed-on: https://go-review.googlesource.com/18977
Reviewed-by: Austin Clements <austin@google.com>
@golang golang locked and limited conversation to collaborators Feb 3, 2017
@rsc rsc removed their assignment Jun 23, 2022
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

5 participants