From a3439c9713608de6c9aca1a40faa5631cc77ab0d Mon Sep 17 00:00:00 2001 From: charviki <48761023+charviki@users.noreply.github.com> Date: Wed, 22 Jun 2022 22:50:42 +0800 Subject: [PATCH] fix: catch server stop error (#2125) Co-authored-by: chenwq --- app.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app.go b/app.go index df992250d..0a5afabc1 100644 --- a/app.go +++ b/app.go @@ -116,15 +116,11 @@ func (a *App) Run() error { c := make(chan os.Signal, 1) signal.Notify(c, a.opts.sigs...) eg.Go(func() error { - for { - select { - case <-ctx.Done(): - return ctx.Err() - case <-c: - if err := a.Stop(); err != nil { - return err - } - } + select { + case <-ctx.Done(): + return nil + case <-c: + return a.Stop() } }) if err := eg.Wait(); err != nil && !errors.Is(err, context.Canceled) {