edouardparis / lntop

:zap: LN terminal dashboard :bar_chart:
MIT License
183 stars 24 forks source link

panic: send on closed channel #77

Closed hieblmi closed 2 years ago

hieblmi commented 2 years ago

A panic I just saw to be investigated:

panic: send on closed channel

goroutine 31 [running]:
github.com/edouardparis/lntop/pubsub.withTickerInfo.func1({0x11b9cf0, 0xc0001ac000}, {0x11bf918, 0xc0001819f0}, 0xc00043d360, 0xc000182e01)
    /home/xxx/lntop/pubsub/ticker.go:44 +0x205
github.com/edouardparis/lntop/pubsub.(*PubSub).ticker.func1()
    /home/xxx/lntop/pubsub/ticker.go:27 +0x130
created by github.com/edouardparis/lntop/pubsub.(*PubSub).ticker
    /home/xxx/lntop/pubsub/ticker.go:18 +0x133
rkfg commented 2 years ago

Most likely misuse of channels. The sub channel is closed in https://github.com/edouardparis/lntop/blob/449811ab43ea2ed947933fc52e648a1ca53730d1/ui/ui.go#L37 and it's incorrect because the same channel is used in pubsub as well. Channels should be closed by writers, not readers and especially not by unrelated entities (in this case UI). It creates a race condition and yeah, it happens sometimes. I propose not closing the event channel at all because it only needs to be closed when the app exits and at that point nothing matters anyway.

rkfg commented 2 years ago

i think this should be closed as completed

hieblmi commented 2 years ago

Fixed in https://github.com/edouardparis/lntop/pull/87.