From b41e4643b428231e1d6fa636ef986617f3a1bfa2 Mon Sep 17 00:00:00 2001 From: Anne Cognet Date: Fri, 17 Nov 2023 14:10:44 -0800 Subject: [PATCH] Panic if the extension is short lived If the extension stops immediately after it starts, there could be a problem where shutdown happened before start. It's something we've seen in integration tests, but may happen or worsen the case where the extension is stuck in a restart loop with osqueryd. --- 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 }