From 916bca33ea6cf2530117071fdd9b7b15e00e2f29 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Wed, 17 May 2023 16:13:43 +0200 Subject: ui: fix deadlocks in message channel There are several ways the ui message channel can fill up leading to deadlocks. 1) Invalidate() changes the value of uiState to DIRTY. The following call sequence: QueueRedraw() Invalidate() QueueRedraw() Leads to multiple nil messages being queued in the message channel whereas one could assume that the second QueueRedraw() would do nothing. This is caused by the tri-state nature of uiState. 2) We use the same channel to convey state change, keyboard events and redraw requests. Since a keyboard event almost always triggers a redraw, we end up trying to append a redraw message in the same goroutine that reads from the channel. This triggers a deadlock when there are more than 50 pending messages. Solve the issue by using multiple channels, one per type of message that needs to be sent to the main ui thread. Remove QueueRedraw() and merge its functionality in Invalidate(). Only use a DIRTY/CLEAN state to determine if something needs to be queued in the redraw channel. Use a channel for quitting instead of an atomic. Restructure some code functions to have a cleaner API. Use a for loop in the main thread and select from all channels. Signed-off-by: Robin Jarry Tested-by: Koni Marti Tested-by: Maarten van Gompel --- commands/term.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'commands/term.go') diff --git a/commands/term.go b/commands/term.go index 64657747..22957635 100644 --- a/commands/term.go +++ b/commands/term.go @@ -43,7 +43,7 @@ func TermCore(aerc *widgets.Aerc, args []string) error { } if tab.Name != title { tab.Name = title - ui.QueueRedraw() + ui.Invalidate() } } term.OnClose = func(err error) { -- cgit