jdevelop / golang-rpi-extras

Some extra interfaces to peripherals found for Arduino and stuff, but in Go and for Raspberry Pi.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Panic in jdevelop/gpio

vkorn opened this issue · comments

Hello,

Sorry for opening issue here, but it's related to jdevelop/gpio fork where I can't open one.

Sometimes gpio lib is panicking due to null in watchEventCallbacks while using rf522:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x5e815528]

goroutine 56 [running]:
github.com/jdevelop/gpio.setupEpoll.func1()
        /go/pkg/mod/github.com/jdevelop/gpio@v0.0.0-20180116031910-0e2cc992019a/gpio_linux.go:81 +0x13c
created by github.com/jdevelop/gpio.setupEpoll
        /go/pkg/mod/github.com/jdevelop/gpio@v0.0.0-20180116031910-0e2cc992019a/gpio_linux.go:67 +0x5c

I would assume that's because Wait was called meanwhile and IrqPin.EndWatch triggers deletion from the map. Maybe it makes sense to mutex it?

Yep, just got another one with more context

fatal error: concurrent map read and map write

goroutine 45 [running]:
runtime.throw(0x5e99decd, 0x21)
        /usr/local/go/src/runtime/panic.go:608 +0x64 fp=0x185f6a0 sp=0x185f68c pc=0x5e8c8220
runtime.mapaccess2_fast32(0x5e9f7f10, 0x157a200, 0xb, 0x10, 0xffffffff)
        /usr/local/go/src/runtime/map_fast32.go:61 +0x1b4 fp=0x185f6b0 sp=0x185f6a0 pc=0x5e8ab310
github.com/jdevelop/gpio.setupEpoll.func1()
        /go/pkg/mod/github.com/jdevelop/gpio@v0.0.0-20180116031910-0e2cc992019a/gpio_linux.go:80 +0x128 fp=0x185f7ec sp=0x185f6b0 pc=0x5e98e514
runtime.goexit()
        /usr/local/go/src/runtime/asm_arm.s:867 +0x4 fp=0x185f7ec sp=0x185f7ec pc=0x23fbc0
created by github.com/jdevelop/gpio.setupEpoll
        /go/pkg/mod/github.com/jdevelop/gpio@v0.0.0-20180116031910-0e2cc992019a/gpio_linux.go:67 +0x5c

I would rather suggest to give it a try for periph

It does work fine with Raspberry Pi Zero / Zero W and has more robust support for IRQ events.