aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-05-25 11:16:13 +0200
committerRobin Jarry <robin@jarry.cc>2022-05-25 22:18:26 +0200
commit57bd9e318b7073692627bd72f067633609e26883 (patch)
tree5eccd6edbf2c1db01121a34884624bbce6fa8faf /widgets
parent0cc992b4e3ed26c0f9f8dab94024985c87853a64 (diff)
downloadaerc-57bd9e318b7073692627bd72f067633609e26883.tar.gz
terminal: fix deadlock with finer-grained locking
Commit 1bac87e80414 ("terminal: fix race when closing a terminal") fixed a race in Terminal.Draw by using a mutex. The current locking of the entire Draw function could create a deadlock, however, since this function itself might call Terminal.Close which is protected by the same mutex. A finer-grained locking solves both the race and deadlock problem. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'widgets')
-rw-r--r--widgets/terminal.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/widgets/terminal.go b/widgets/terminal.go
index 1d4c1df3..e499e3e4 100644
--- a/widgets/terminal.go
+++ b/widgets/terminal.go
@@ -232,9 +232,6 @@ func (term *Terminal) invalidate() {
}
func (term *Terminal) Draw(ctx *ui.Context) {
- term.closeMutex.Lock()
- defer term.closeMutex.Unlock()
-
if term.destroyed {
return
}
@@ -252,7 +249,15 @@ func (term *Terminal) Draw(ctx *ui.Context) {
if term.pty == nil {
term.vterm.SetSize(ctx.Height(), ctx.Width())
+
+ term.closeMutex.Lock()
+ if term.cmd == nil {
+ term.closeMutex.Unlock()
+ return
+ }
tty, err := pty.StartWithAttrs(term.cmd, &winsize, &syscall.SysProcAttr{Setsid: true, Setctty: true, Ctty: 1})
+ term.closeMutex.Unlock()
+
term.pty = tty
if err != nil {
term.Close(err)