app.Suspend() deadlocks cview
Closedopened 2 years ago by flowchartsman · 6 comments
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Similar to this tview issue, calling
app.Suspend()to shell out to a program like vim leaves an application in a completely unresponsive busy loop of some kind. The behavior is exactly the same, and can be easily reproduced with the following program, which I am running on MacOS Catalina:
I'll note that debugging this issue is very tetchy, and I was only able to make the barest of headway by attaching to the running process with
dlv, but, funnily enough, stepping through did not reproduce the issue, and attempting to issue a debugger pause after it happend, found me at random locations within tcell or cview lower-level drawing functions, leading me to believe that this is a subtle race condition bug, and with the number of mutexes getting thrown around, I found it pretty daunting to continue, not being familiar with either codebase.
Thanks for reporting this. I have updated Application.Suspend to suspend and resume the screen, rather than finalize it and create an entirely new screen. This gets us closer to what we want, but there is still an issue. When suspending, the screen waits for a mouse or key event before actually suspending. I have an idea of why this is (blocking on PollEvent causes the suspend to hang until PollEvent returns), but I will need to spend some more time on this to be sure.
So does this mean it will appear to the user to freeze until a key is hit? Hmm. Is there an empty event that can be sent to PollEvent that would obviate that?
I've confirmed that the inputLoop is the issue. When suspending, the
inputLoopmust both return.
inputLoopwill only return once it has read something, because it blocks on
Read. Rather than polling stdin directly,
/dev/ttyis polled (on UNIX at least). I have tried opening
/dev/ttyin non-blocking mode to no effect. I will bring this up with tcell's author and see if we can solve it together.
With the recent commit, I've updated cview to only poll the screen between queued updates. This does not resolve the issue for some reason, as far as I can tell cview is copying the tcell mouse.go example. I will look into this more before submitting a bug in case I am missing something.
I've submitted the following PR to resolve this upstream.