fix: lifecycle — clear shutdown flag on startup, document waiter goroutine

- ServiceStartup clears c.shutdown so Core supports restart cycles
- ServiceShutdown waiter goroutine documented as inherent to sync.WaitGroup

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Snider 2026-03-20 17:56:21 +00:00
parent 61b034335a
commit 629adb056b

View file

@ -33,6 +33,7 @@ func (r *ServiceRuntime[T]) Config() *Config { return r.core.Config() }
// ServiceStartup runs OnStart for all registered services that have one.
func (c *Core) ServiceStartup(ctx context.Context, options any) Result {
c.shutdown.Store(false)
startables := c.Startables()
if startables.OK {
for _, s := range startables.Value.([]*Service) {
@ -54,7 +55,9 @@ func (c *Core) ServiceShutdown(ctx context.Context) Result {
c.shutdown.Store(true)
c.ACTION(ActionServiceShutdown{})
// Drain background tasks before stopping services
// Drain background tasks before stopping services.
// On timeout, the waiter goroutine persists until tasks complete —
// this is inherent to sync.WaitGroup (no cancel mechanism).
done := make(chan struct{})
go func() {
c.wg.Wait()