From 68a29c92848397e642e060a83f8a1bd7bd979af2 Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Sun, 17 Nov 2024 23:10:20 +1100 Subject: [PATCH] Prevent infinite loop when using `on-quit` (#1856) --- app.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app.go b/app.go index 45e0dbd2..8fd2066f 100644 --- a/app.go +++ b/app.go @@ -35,6 +35,7 @@ type app struct { menuCompInd int selectionOut []string watch *watch + quitting bool } func newApp(ui *ui, nav *nav) *app { @@ -66,6 +67,14 @@ func newApp(ui *ui, nav *nav) *app { } func (app *app) quit() { + // Using synchronous shell commands for `on-quit` can cause this to be + // called again, so a guard variable is introduced here to prevent an + // infinite loop. + if app.quitting { + return + } + app.quitting = true + onQuit(app) if gOpts.history {