Skip to content

runtime: Fault when allocating byte slice in anonymous goroutine function #5353

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
kisielk opened this issue Apr 25, 2013 · 2 comments
Closed

Comments

@kisielk
Copy link
Contributor

kisielk commented Apr 25, 2013

Go version:

What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
1. go get github.com/kisielk/vigo
2. cd $GOPATH/github.com/kisielk/vigo
3. go build
4. ./vigo 2> trace

The stack trace is here:

unexpected fault address 0xc1c46c1668
fatal error: fault
[signal 0xb code=0x1 addr=0xc1c46c1668 pc=0x40c590]
 
goroutine 4 [running]:
[fp=0xc200059ed0] runtime.throw(0x596d97)
        /home/kamil/go/src/pkg/runtime/panic.c:473 +0x67
[fp=0xc200059ee8] runtime.sigpanic()
        /home/kamil/go/src/pkg/runtime/os_linux.c:239 +0xe7
[fp=0xc20005a288] scanblock(0x7f27611d9000, 0x7f27611d9048, 0x2, 0x1)
        /home/kamil/go/src/pkg/runtime/mgc0.c:800 +0xa00
[fp=0xc20005a3b8] gc(0x7f27612e7e04)
        /home/kamil/go/src/pkg/runtime/mgc0.c:2001 +0x2c5
----- stack segment boundary -----
[fp=0x7f27612e7e18] runtime.gc(0xc200000000)
        /home/kamil/go/src/pkg/runtime/mgc0.c:1927 +0x11b
[fp=0x7f27612e7e70] runtime.mallocgc(0x80, 0x100000001, 0x1)
        /home/kamil/go/src/pkg/runtime/zmalloc_linux_amd64.c:101 +0x1e4
[fp=0x7f27612e7ea8] makeslice1(0x4afc40, 0x80, 0x80, 0x7f27612e7ef0)
        /home/kamil/go/src/pkg/runtime/slice.c:61 +0x89
[fp=0x7f27612e7ed8] runtime.makeslice(0x4afc40, 0x80, 0x80, 0x0, 0x80, ...)
        /home/kamil/go/src/pkg/runtime/slice.c:34 +0x9a
[fp=0x7f27612e7fb8] github.com/nsf/termbox-go.func·001()
        /home/kamil/src/github.com/nsf/termbox-go/api.go:84 +0x3e
[fp=0x7f27612e7fc0] runtime.goexit()
        /home/kamil/go/src/pkg/runtime/proc.c:1223
created by github.com/nsf/termbox-go.Init
        /home/kamil/src/github.com/nsf/termbox-go/api.go:101 +0x66f
 
goroutine 1 [chan receive]:
github.com/kisielk/vigo/editor.(*editor).Loop(0xc20009f000, 0xc2000472d0, 0x0)
        /home/kamil/src/github.com/kisielk/vigo/editor/editor.go:435 +0x61
main.main()
        /home/kamil/src/github.com/kisielk/vigo/main.go:26 +0x18c
 
goroutine 3 [syscall]:
os/signal.loop()
        /home/kamil/go/src/pkg/os/signal/signal_unix.go:21 +0x1c
created by os/signal.init·1
        /home/kamil/go/src/pkg/os/signal/signal_unix.go:27 +0x2f
 
goroutine 5 [runnable]:
main.func·001()
        /home/kamil/src/github.com/kisielk/vigo/main.go:21
created by main.main
        /home/kamil/src/github.com/kisielk/vigo/main.go:25 +0x179

The relevant part of termbox-go/api.go:
   
   83     go func() {
   84         buf := make([]byte, 128)
   85         for {
   86             select {
   87             case <-sigio:
   88                 for {
   89                     n, err := syscall.Read(in, buf)
   90                     if err == syscall.EAGAIN || err == syscall.EWOULDBLOCK {
   91                         break
   92                     }
   93                     input_comm <- input_event{buf[:n], err}
   94                     ie := <-input_comm
   95                     buf = ie.data[:128]
   96                 }
   97             case <-quit:
   98                 return
   99             }
  100         }
  101     }()

The program depends on termbox-go, for which the code is at github.com/nsf/termbox-go
Note that it uses unsafe in a few places to make some syscalls to determine terminal
size.

There is no crash with GOGC=off. Also if I check out theprevious revision of the vigo
project, before I moved things from package main to a subpackage, there is no crash
either. The code runs fine when compiled with go1.0.2 on the same machine.

Sorry I couldn't provide a smaller test case at this point, but let me know if I can do
anything to narrow it down.

Which compiler are you using (5g, 6g, 8g, gccgo)?
8g

Which operating system are you using?
Ubuntu 12.10 64-bit, Mac OS X 10.8

Which version are you using?  (run 'go version')

go version devel +0c16e97c7587 Thu Apr 25 13:23:24 2013 +0900 linux/amd64
@kisielk
Copy link
Contributor Author

kisielk commented Apr 25, 2013

Comment 2:

I guess the title is a bit misleading. I tried changing the termbox code so that the
function is not anonymous any more but still get the same error.

@dvyukov
Copy link
Member

dvyukov commented Apr 25, 2013

Comment 3:

The bad gcinfo is generated for io.ioutil/blackHoleBuf
https://golang.org/cl/8929044 turns it into compilation error.
https://golang.org/cl/8663052 seems to fix the crash.

Owner changed to @dvyukov.

Status changed to Duplicate.

Merged into issue #5291.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
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