diff --git a/svloc.go b/svloc.go index 124048d..93f871c 100644 --- a/svloc.go +++ b/svloc.go @@ -346,6 +346,7 @@ func (u *universeData) cloneShutdownFuncList() []func() { funcList := make([]func(), len(u.shutdownFuncs)) copy(funcList, u.shutdownFuncs) + u.shutdownFuncs = nil u.alreadyShutdown = true return funcList } diff --git a/svloc_test.go b/svloc_test.go index 00dad60..973b9ee 100644 --- a/svloc_test.go +++ b/svloc_test.go @@ -813,4 +813,24 @@ func TestUniverse_CleanUp(t *testing.T) { }) assert.Equal(t, errors.New("svloc: can NOT call 'Wrap' after 'CleanUp'"), err) }) + + t.Run("success shutdown after clean up", func(t *testing.T) { + var shutdowns []string + repoLoc := Register[Repo](func(unv *Universe) Repo { + unv.OnShutdown(func() { + shutdowns = append(shutdowns, "repo") + }) + return &UserRepo{} + }) + + unv := NewUniverse() + + repoLoc.Get(unv) + + unv.CleanUp() + + unv.Shutdown() + + assert.Equal(t, []string{"repo"}, shutdowns) + }) }