mirror of
https://github.com/turbot/steampipe.git
synced 2025-12-23 21:09:15 -05:00
* Add test demonstrating bug #4782 - Shutdown panics with nil pool Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix #4782: Add nil pool check in PluginManager.Shutdown Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user