Currently the terminal widget can be closed while it's also being
updated leading to a SIGSEGV: https://todo.sr.ht/~sircmpwn/aerc2/449.
This patch adds the minimal amount of locking to make that impossible.
---
widgets/terminal.go | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/widgets/terminal.go b/widgets/terminal.go
index 0277521..8618b1e 100644
--- a/widgets/terminal.go+++ b/widgets/terminal.go
@@ -9,7 +9,7 @@ import (
"git.sr.ht/~sircmpwn/aerc/lib/ui"
"github.com/creack/pty"
- "github.com/ddevault/go-libvterm"+ vterm "github.com/ddevault/go-libvterm" "github.com/gdamore/tcell/v2"
)
@@ -105,6 +105,7 @@ type Terminal struct {
damage []vterm.Rect // protected by damageMutex
damageMutex sync.Mutex
writeMutex sync.Mutex
+ closeMutex sync.Mutex // Only necessary around cmd/pty changes
If you reach this the lock never gets released
> }
> }
> term.closeMutex.Unlock()
PS: Can't we force all close events to go over the UI thread?
Why do we even have asynchronous close events for the terminal?
If we could synchronize this it may be much simpler to understand / maintain.
And yes, that's just an idea I'm throwing into the void, I didn't look at the
code all to closely.
Cheers,
Reto