mattn / go-tty

MIT License
208 stars 18 forks source link

prevent `panic: send on closed channel` during termination #15

Closed azr closed 5 years ago

azr commented 5 years ago

sometimes it's possible to receive a SIGWINCH right in between when close(tty.ss) and close(tty.ws) are being called, causing a panic.

Making the WINSIZE production goroutine close the chan will prevent this.

srlehn commented 5 years ago

demo code here: https://github.com/mattn/go-tty/issues/19

srlehn commented 5 years ago

required by PR: https://github.com/gizak/termui/pull/233

mattn commented 5 years ago

I don't think this is right since ws must trigger several time.

srlehn commented 5 years ago

I only know that this definitely fixes the crashes for me. The crash happens spontaneously after resizing for a while.

azr commented 5 years ago

Hey @mattn, ss takes all sigwinch syscalls but ss must be depleted before we close ws, otherwise panic: send on a closed channel. The PR ensures ss is depleted before we close ws since the close will only happen after the range.

defer close(tty.ws)
for sig := range tty.ss {
mattn commented 5 years ago

I just understood what is happening with your explanation.

mattn commented 5 years ago

Thank you

azr commented 5 years ago

Thanks !! Sorry, my first explanation was not the clearest 🙂