From 61ac79279aaa3e119940707816ba90c3dd5c5cb3 Mon Sep 17 00:00:00 2001 From: a-cognet <85908831+a-cognet@users.noreply.github.com> Date: Thu, 30 Nov 2023 11:57:33 -0800 Subject: [PATCH] Shutdown correctly if the extension is short lived (#120) --- server.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server.go b/server.go index 29d0007..5541e8c 100644 --- a/server.go +++ b/server.go @@ -196,6 +196,10 @@ func (s *ExtensionManagerServer) Start() error { err := func() error { s.mutex.Lock() defer s.mutex.Unlock() + // check after the lock the serverClient is present. It could have gone away on very short restart loops + if s.serverClient == nil { + return errors.New("cannot start, shutdown in progress") + } registry := s.genRegistry() stat, err := s.serverClient.RegisterExtension( @@ -278,9 +282,7 @@ func (s *ExtensionManagerServer) Run() error { }() err := <-errc - if err := s.Shutdown(context.Background()); err != nil { - return err - } + _ = s.Shutdown(context.Background()) return err }