go-ble / ble

Bluetooth Low Energy for Linux / macOS
BSD 3-Clause "New" or "Revised" License
305 stars 109 forks source link

Hanging on ble.Connect #86

Open mnadel opened 3 years ago

mnadel commented 3 years ago

I'm trying to search for and connect to a BLE device (from a Pi) in a loop w/ a connect timeout, and it always eventually hangs with the below goroutine trace.

The connect is being called with a timeout context:

ctx := ble.WithSigHandler(context.WithTimeout(context.Background(), time.Second*5))
cln, err := ble.Connect(ctx, pm5.filterAdvert)
goroutine 27 [chan receive, 26 minutes]:
github.com/go-ble/ble.Connect(0x5ec7dc, 0x17eea08, 0x1900998, 0x1, 0x1, 0x1900940, 0x5ec7dc)
        /home/pi/go/pkg/mod/github.com/go-ble/ble@v0.0.0-20210519192345-b055c211937b/gatt.go:147 +0x1a4
<truncated>

goroutine 1083 [syscall, 26 minutes]:
syscall.Syscall(0x3, 0x7, 0x1876000, 0x1000, 0x469ce4, 0x17ee608, 0x0)
        /usr/local/go/src/syscall/asm_linux_arm.s:14 +0x8
golang.org/x/sys/unix.read(0x7, 0x1876000, 0x1000, 0x1000, 0x1876000, 0x7, 0x15b4668)
        /home/pi/go/pkg/mod/golang.org/x/sys@v0.0.0-20210603081109-ebe580a85c40/unix/zsyscall_linux.go:1242 +0x40
golang.org/x/sys/unix.Read(...)
        /home/pi/go/pkg/mod/golang.org/x/sys@v0.0.0-20210603081109-ebe580a85c40/unix/syscall_unix.go:157
github.com/go-ble/ble/linux/hci/socket.(*Socket).Read(0x17ee600, 0x1876000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
        /home/pi/go/pkg/mod/github.com/go-ble/ble@v0.0.0-20210519192345-b055c211937b/linux/hci/socket/socket.go:123 +0x50
github.com/go-ble/ble/linux/hci.(*HCI).sktLoop(0x1504240)
        /home/pi/go/pkg/mod/github.com/go-ble/ble@v0.0.0-20210519192345-b055c211937b/linux/hci/hci.go:300 +0x90
created by github.com/go-ble/ble/linux/hci.(*HCI).Init
        /home/pi/go/pkg/mod/github.com/go-ble/ble@v0.0.0-20210519192345-b055c211937b/linux/hci/hci.go:153 +0x4cc

goroutine 1084 [select, 26 minutes]:
github.com/go-ble/ble/linux/hci.(*HCI).Accept(0x1504240, 0x16f20c0, 0x4, 0x1, 0x16f20c0)
        /home/pi/go/pkg/mod/github.com/go-ble/ble@v0.0.0-20210519192345-b055c211937b/linux/hci/gap.go:185 +0xac
github.com/go-ble/ble/linux.loop(0x1504240, 0x17dc200, 0x203)
        /home/pi/go/pkg/mod/github.com/go-ble/ble@v0.0.0-20210519192345-b055c211937b/linux/device.go:55 +0x1c
created by github.com/go-ble/ble/linux.NewDeviceWithNameAndHandler
        /home/pi/go/pkg/mod/github.com/go-ble/ble@v0.0.0-20210519192345-b055c211937b/linux/device.go:48 +0x230
estutzenberger commented 2 years ago

I'm not sure if this is still and issue for you but you might consider seeing if the same behavior happens in the better patched library at https://github.com/rigado/ble.

Hope this helps.

Jan21493 commented 2 months ago

I know this is issue is quite old, but if somebody has the same, have a look at https://github.com/go-ble/ble/pull/112 or https://github.com/rigado/ble/pull/76