Skip to content

Commit

Permalink
Panic if the extension is short lived
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
a-cognet committed Nov 17, 2023
1 parent e3cde12 commit b41e464
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit b41e464

Please sign in to comment.