From e75e5508c51291172a01f786626ef79334b5f80f Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Sun, 10 Dec 2023 11:52:58 +0000 Subject: [PATCH] improve graceful shutdown process --- cmd/dmsgweb/commands/dmsgweb.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/dmsgweb/commands/dmsgweb.go b/cmd/dmsgweb/commands/dmsgweb.go index bdad1a58..edc2fa6a 100644 --- a/cmd/dmsgweb/commands/dmsgweb.go +++ b/cmd/dmsgweb/commands/dmsgweb.go @@ -161,6 +161,13 @@ var RootCmd = &cobra.Command{ } defer closeDmsg() + go func() { + <-ctx.Done() + cancel() + closeDmsg() + os.Exit(0) //this should not be necessary + }() + httpC = http.Client{Transport: dmsghttp.MakeHTTPTransport(ctx, dmsgC)} // Create a SOCKS5 server with custom name resolution @@ -262,10 +269,6 @@ var RootCmd = &cobra.Command{ wg.Done() }() wg.Wait() - os.Exit(0) //this should not be necessary - // <-ctx.Done() - cancel() - closeDmsg() }, }