Skip to content

Non-blocking select with more than one channel segfaults on arm #2401

@jmckaskill

Description

@jmckaskill
What steps will reproduce the problem?
1. Compile and run the following test program which panics (see below). The extra go
routine is to stop the deadlock detection.

package main

import "time"

func main() {
    ch1 := make(chan bool)
    ch2 := make(chan bool)
    go func() {
        time.Sleep(3e9)
        ch1 <- true
    }()

    select {
    case <-ch1:
    case <-ch2:
    default:
    }
}

2. Split the non blocking select into two consecutive calls and it succeeds:
package main

import "time"

func main() {
    ch1 := make(chan bool)
    ch2 := make(chan bool)
    go func() {
        time.Sleep(3e9)
        ch1 <- true
    }()
    select {
    case <-ch1:
    default:
    }

    select {
    case <-ch2:
    default:
    }
}

What is the expected output?
Nothing

What do you see instead?
unexpected fault address 0x15d01078
throw: fault
[signal 0xb code=0x2 addr=0x15d01078 pc=0x14960]

goroutine 1 [running]:
main.main()
    /Users/james/g/src/test/test.go:13 +0x130

goroutine 2 [runnable]:
main._func_001(0x10500180, 0x0)
    /Users/james/g/src/test/test.go:11
created by main.main
    /Users/james/g/src/test/test.go:11 +0xa0


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

Which operating system are you using?
custom arm linux based off of timesys (equivalent of buildroot et all)
uname -a:
Linux torch-5112522801 2.6.27-ts-armv5l_trimble-PR3 #201 PREEMPT Tue Jan 18 15:57:53 MST
2011 armv5tejl unknown

Which revision are you using?  (hg identify)
weekly
be3b74cabc5d

Please provide any additional information below.

Running the test executable through objdump the offending asm seems to be in runtime.xch:

00014958 <runtime.xchg>:
   14958:       e52de014        str     lr, [sp, #-20]!
   1495c:       e59d1018        ldr     r1, [sp, #24]
   14960:       e5911000        ldr     r1, [r1]

Running with runtime.showframe returning 1 gives the following stack dump:

unexpected fault address 0x15d01078
throw: fault
[signal 0xb code=0x2 addr=0x15d01078 pc=0x14960]

goroutine 1 [running]:
runtime.throw(0x6e04a, 0x15d01078)
    /Users/james/go/src/pkg/runtime/runtime.c:114 +0x40
runtime.sigpanic()
    /Users/james/go/src/pkg/runtime/linux/thread.c:306 +0xc0
runtime.xchg(0x15d01078, 0x1, 0x100)
    /Users/james/go/src/pkg/runtime/arm/atomic.c:29 +0x8
futexlock(0x15d01078, 0x15c04)
    /Users/james/go/src/pkg/runtime/linux/thread.c:125 +0x30
runtime.lock(0x15d01078, 0x15d01050)
    /Users/james/go/src/pkg/runtime/linux/thread.c:187 +0x4c
sellock(0x1050e000, 0x40000000)
    /Users/james/go/src/pkg/runtime/chan.c:764 +0xbc
selectgo(0x40040fac, 0x4)
    /Users/james/go/src/pkg/runtime/chan.c:850 +0x268
runtime.selectgo(0x1050e000, 0x10501500)
    /Users/james/go/src/pkg/runtime/chan.c:803 +0x10
main.main()
    /Users/james/g/src/test/test.go:13 +0x130
runtime.mainstart()
    /Users/james/go/src/pkg/runtime/arm/asm.s:68 +0x14

goroutine 2 [runnable]:
main._func_001(0x10500180, 0x0)
    /Users/james/g/src/test/test.go:11
runtime.goexit()
    /Users/james/go/src/pkg/runtime/proc.c:236
created by main.main
    /Users/james/g/src/test/test.go:11 +0xa0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions