mirror of
https://github.com/henrygd/beszel.git
synced 2026-08-19 08:47:46 +02:00
The staggered Initialize goroutine kept calling AddSystem after the hub had been torn down, which spawned StartUpdater goroutines that later dereferenced a nil DB inside PocketBase. Track a manager-level context that RemoveAllSystems cancels, abort the staggered loop on shutdown, and refuse AddSystem once the manager is stopped.
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
package systems
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/henrygd/beszel/internal/entities/system"
|
||||
"github.com/pocketbase/pocketbase/tools/store"
|
||||
)
|
||||
|
||||
func TestCombinedData_MigrateDeprecatedFields(t *testing.T) {
|
||||
@@ -157,3 +159,20 @@ func TestCombinedData_MigrateDeprecatedFields(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestAddSystemRefusedAfterShutdown verifies that AddSystem returns an error
|
||||
// once the manager has been shut down, so the staggered Initialize starter
|
||||
// cannot spawn updater goroutines against a torn-down hub. See #1950.
|
||||
func TestAddSystemRefusedAfterShutdown(t *testing.T) {
|
||||
sm := &SystemManager{systems: store.New(map[string]*System{})}
|
||||
sm.ctx, sm.cancel = context.WithCancel(context.Background())
|
||||
sm.cancel()
|
||||
|
||||
err := sm.AddSystem(&System{Id: "sys", Host: "127.0.0.1"})
|
||||
if err == nil {
|
||||
t.Fatalf("AddSystem returned nil error after shutdown")
|
||||
}
|
||||
if sm.systems.Has("sys") {
|
||||
t.Fatalf("system was added to store after shutdown")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user