Skip to content

Commit

Permalink
Merge 06ef63f into 1a3f275
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jin-gou authored Aug 25, 2022
2 parents 1a3f275 + 06ef63f commit a3ad012
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
11 changes: 0 additions & 11 deletions pkg/app/server/hertz.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func Default(opts ...config.Option) *Hertz {
func (h *Hertz) Spin() {
errCh := make(chan error)
h.initOnRunHooks(errCh)
h.initOnShutdownHooks()
go func() {
errCh <- h.Run()
}()
Expand Down Expand Up @@ -133,13 +132,3 @@ func (h *Hertz) initOnRunHooks(errChan chan error) {
return nil
})
}

func (h *Hertz) initOnShutdownHooks() {
opt := h.GetOptions()
// add deregister func to shutdownHooks
h.OnShutdown = append(h.OnShutdown, func(ctx context.Context) {
if err := opt.Registry.Deregister(opt.RegistryInfo); err != nil {
hlog.Errorf("HERTZ: Deregister error=%v", err)
}
})
}
8 changes: 8 additions & 0 deletions pkg/route/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ func (engine *Engine) Shutdown(ctx context.Context) (err error) {
}(i)
}

opt := engine.options
if opt.Registry != nil {
if err = opt.Registry.Deregister(opt.RegistryInfo); err != nil {
hlog.Errorf("HERTZ: Deregister error=%v", err)
return err
}
}

// call transport shutdown
if err := engine.transport.Shutdown(ctx); err != ctx.Err() {
return err
Expand Down

0 comments on commit a3ad012

Please sign in to comment.