~sircmpwn/aerc

Avoid race condition in terminal close v1 PROPOSED

y0ast: 1
 Avoid race condition in terminal close

 1 files changed, 3 insertions(+), 3 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/aerc/patches/20265/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Avoid race condition in terminal close Export this patch

---
Should fix: https://todo.sr.ht/~sircmpwn/aerc2/449

Much simpler than using mutexes, and I think this should be sufficient.
By setting `term.closed = true` as first thing, there is no moment where
`termin.closed == false && term.cmd == nil` so we avoid crashes in pty.

 widgets/terminal.go | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/widgets/terminal.go b/widgets/terminal.go
index f47f671..6bee46d 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"
)

@@ -175,6 +175,7 @@ func (term *Terminal) Close(err error) {
	if term.closed {
		return
	}
	term.closed = true
	term.err = err
	if term.pty != nil {
		term.pty.Close()
@@ -185,10 +186,9 @@ func (term *Terminal) Close(err error) {
		term.cmd.Wait()
		term.cmd = nil
	}
	if !term.closed && term.OnClose != nil {
	if term.OnClose != nil {
		term.OnClose(err)
	}
	term.closed = true
	term.ctx.HideCursor()
}

-- 
2.24.3 (Apple Git-128)
A few notes on this patch. (Note that I am not one of the maintainers, though)