diff --git a/pkg/pluginmanager_service/plugin_manager.go b/pkg/pluginmanager_service/plugin_manager.go index aa03c9fff..8e6f808bc 100644 --- a/pkg/pluginmanager_service/plugin_manager.go +++ b/pkg/pluginmanager_service/plugin_manager.go @@ -266,8 +266,10 @@ func (m *PluginManager) Shutdown(*pb.ShutdownRequest) (resp *pb.ShutdownResponse m.startPluginWg.Wait() // close our pool - log.Printf("[INFO] PluginManager closing pool") - m.pool.Close() + if m.pool != nil { + log.Printf("[INFO] PluginManager closing pool") + m.pool.Close() + } m.mut.RLock() defer func() { @@ -798,9 +800,14 @@ func (m *PluginManager) updateConnectionSchema(ctx context.Context, connectionNa // also send a postgres notification notification := steampipeconfig.NewSchemaUpdateNotification() + if m.pool == nil { + log.Printf("[WARN] cannot send schema update notification: pool is nil") + return + } conn, err := m.pool.Acquire(ctx) if err != nil { log.Printf("[WARN] failed to send schema update notification: %s", err) + return } defer conn.Release() diff --git a/pkg/pluginmanager_service/plugin_manager_test.go b/pkg/pluginmanager_service/plugin_manager_test.go index 5e1876415..eb218a5f6 100644 --- a/pkg/pluginmanager_service/plugin_manager_test.go +++ b/pkg/pluginmanager_service/plugin_manager_test.go @@ -747,3 +747,29 @@ func TestPluginManager_OnConnectionConfigChanged_EmptyToNonEmpty(t *testing.T) { t.Logf("Expected error when pool is nil: %v", err) } } + +// TestPluginManager_Shutdown_NoPlugins tests that Shutdown handles nil pool gracefully +// Related to bug #4782 +func TestPluginManager_Shutdown_NoPlugins(t *testing.T) { + // Create a PluginManager without initializing the pool + // This simulates a scenario where pool initialization failed + pm := &PluginManager{ + logger: hclog.NewNullLogger(), + runningPluginMap: make(map[string]*runningPlugin), + connectionConfigMap: make(connection.ConnectionConfigMap), + plugins: make(connection.PluginMap), + // Note: pool is not initialized, will be nil + } + + // Calling Shutdown should not panic even with nil pool + req := &pb.ShutdownRequest{} + resp, err := pm.Shutdown(req) + + if err != nil { + t.Errorf("Shutdown returned error: %v", err) + } + + if resp == nil { + t.Error("Shutdown returned nil response") + } +}