From 5340848de44f990e7875bbcb180316a9cd81b3bf Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Fri, 6 Sep 2024 15:46:57 -0700 Subject: [PATCH] vtbackup: allow exiting if failing early The control flow in here relies on panic'ing and recovering from that panic. Exiting the process ends up being blocked on this defer block before the panic recovery handler if we exit before `servenv.ExitChan` is created. We're then ultimately blocking forever and require a kill -9 while we're trying to write into a nil channel. This is ultimately becuase we start up `servenv.RunDefault()` in a goroutine, and `servenv.ExitChan` ends up being created within that, so it's possible we are trying to exit before the channel is created. Signed-off-by: Matt Robenolt --- go/cmd/vtbackup/cli/vtbackup.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/go/cmd/vtbackup/cli/vtbackup.go b/go/cmd/vtbackup/cli/vtbackup.go index 1b61c886ae7..733599cc6c1 100644 --- a/go/cmd/vtbackup/cli/vtbackup.go +++ b/go/cmd/vtbackup/cli/vtbackup.go @@ -230,8 +230,10 @@ func run(cc *cobra.Command, args []string) error { }) defer func() { - servenv.ExitChan <- syscall.SIGTERM - <-ctx.Done() + if servenv.ExitChan != nil { + servenv.ExitChan <- syscall.SIGTERM + <-ctx.Done() + } }() go servenv.RunDefault()