mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #179] Freeze and Crash #139
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#139
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @aunoor on GitHub (Nov 7, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/179
Hi!
New ability to send redraw request to app is cool, but adding second event loop is not.
Crush
App crush on exit. Just Ctrl-C and we see panic trace.
It happened because screen is gone in Stop(), but event queue still have tcell.EventResize.
Freeze
Let take Box example and change it a bit:
As you can see, I add input handler on app level. It just eat Ctrl-C and allow quit on Ctrl-Q.
Build, run. Ctrl-C - and we going to endless loop somewhere around EventLoop: label
Exit by Ctrl-Q working as expected, but it strange: on my more complex app any call of Application.Stop() cause panic.
Why adding more complicated mechanism if there is already simple, reliable and extendable tcell.PostEvent()?
@3cb commented on GitHub (Nov 9, 2018):
I think I found the issue with Ctrl-C:
github.com/rivo/tview@61a4cf388a/application.go (L219)Returning
nilfrominputCapturebreaks theEventLooprather than continuing to the next iteration. Replacingbreak EventLoopwithcontinuefixes the above example.This is a good question and I'm not sure why it didn't occur to me when I suggested the current design. We should probably use
tcell.PostEventWait()in a separate goroutine so that updates don't get dropped but it should still reduce the complexity. I think it's possible without breaking the API as well. I'll take a shot at it this weekend.@rivo commented on GitHub (Nov 10, 2018):
Thanks for catching this. Yes, the
breakwas wrong. I fixed that.How does using
tcell.PostEventWait()help with syncing updates and events? It's probably better to queue events using this function than to post them to our own channel (and sincetcell.PollEvent()is already in its own goroutine, we probably don't need another goroutine fortcell.PostEventWait()). But we still have to make sure that updates don't interfere with events. So I would think most of what we did here will remain the same.Or is there something I'm not seeing here?
@aunoor commented on GitHub (Nov 10, 2018):
After update to last master my example start to generate next panic trace:
On first glance it look simple, and I change
to
and got next:
May be I do something wrong?
OS: Windows 10
Go: go version go1.11.1 windows/386
@3cb commented on GitHub (Nov 12, 2018):
What happens when you do the following instead?
@aunoor commented on GitHub (Nov 13, 2018):
application.go:240 is
screen.Clear()@3cb commented on GitHub (Nov 13, 2018):
This happens when you call
Application.Stop()directly from another go routine?@aunoor commented on GitHub (Nov 13, 2018):
No, as you can see in example from my first post,
Application.Stop()called from main thread, inside inputCapture function. Moreover, unmodified Box example also panic on Ctrl-C.Windows: panic
Fedora linux, go version go1.10.4 linux/386 in system console (no X): all ok, no panic
@aunoor commented on GitHub (Nov 13, 2018):
Small update: OpenSuse 15.1 under WSL, go version go1.9.7 linux/amd64: no panic.
@rivo commented on GitHub (Nov 19, 2018):
On Windows, it appears that upon calling
Screen.Fini(),tcellsends a "resize" event to the event queue before sendingnilwhereas on other platforms, that "resize" event is not sent. (@gdamore: Not sure if this is intentional.)I fixed the code to deal with this. With your example, I'm not getting a deadlock anymore on Windows.
@3cb commented on GitHub (Nov 19, 2018):
I think this fix is causing unpredictable behavior when using
app.Suspend().Given the following code, sometimes hitting keys sometimes prevents
Suspendfrom returning and allowing the box to be redrawn; the application will just close:Again, it doesn't happen every time but something seems off.
@gdamore commented on GitHub (Nov 19, 2018):
@rivo I don't recall that it was intentional. I'll have to look.
@rivo commented on GitHub (Nov 26, 2018):
@3cb, thanks. This whole thing just became too complex. I rearranged the code somewhat so it can also deal with the extra resize event on Windows even during suspended mode.
My tests (regular and suspended mode) didn't show any problems on Windows and on macOS. If you catch anything, let me know.
@3cb commented on GitHub (Nov 28, 2018):
@rivo, No problem. I took some time to explore using
screen.PostEvent()like I mentioned above. I had to add some private types to get tview-specific events(updates, suspend, stop) to implement thetcell.Eventinterface but I think it makes the flow of events into the main event loop easier to reason about. Hopefully, I will find some time tomorrow to submit a PR just so you can take a look to see if you think it is worthwhile to pursue.@rivo commented on GitHub (Dec 3, 2018):
It looks like you didn't start with the recent modifications I made. Your PR re-introduces old code and variables which I had already removed in favour of simplification. I'm not planning on going back to the old version, mostly because it had bugs that caused issues on Windows, but also because it was unnecessarily complex.
If you'd like to submit changes, I suggest you start with the current codebase as the code has changed significantly since we started this discussion.
I have to say I'm reasonably happy with the current
Applicationcode. (With the disclaimer that I haven't understood yet howScreen.PostEvent()can help us with updates in goroutines. Maybe there's something I'm not seeing at the moment.)@3cb commented on GitHub (Dec 3, 2018):
Sorry about that. I don't think I submitted a PR. All I did was push to my fork of the repo and then delete it; didn't know it would automatically create a notification in this issue.
As far as using
PostEvent(): What you did with thescreenReplacementchannel requires less code so I decided not to submit a PR. I did, however, realize there is potential for deadlock ifapp.QueueUpdateis called frominputCapture. So I'll open a new issue for that.@rivo commented on GitHub (Dec 3, 2018):
Ok, that was a misunderstanding then. I thought it was a new submission.