From 906a9ead4fe30611cf0408d0b5ead8da607f95ed Mon Sep 17 00:00:00 2001 From: longxboy Date: Mon, 6 Sep 2021 21:31:33 +0800 Subject: [PATCH] fix:reuse parent ctx cause unexpected stop of App (#1429) * fix reuse parent ctx cause unexpected stop of App --- app.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app.go b/app.go index fbae6a01b..10a43dbce 100644 --- a/app.go +++ b/app.go @@ -99,10 +99,9 @@ func (a *App) Run() error { } wg.Wait() if a.opts.registrar != nil { - var cancel context.CancelFunc - ctx, cancel = context.WithTimeout(a.opts.ctx, a.opts.registrarTimeout) - defer cancel() - if err := a.opts.registrar.Register(ctx, instance); err != nil { + rctx, rcancel := context.WithTimeout(a.opts.ctx, a.opts.registrarTimeout) + defer rcancel() + if err := a.opts.registrar.Register(rctx, instance); err != nil { return err } a.instance = instance