H-A-480 b: the composer's watch ends with the agent's stop

The composer's loop and its hearers outlived the node agent's run and logged after
it ended; the node agent now waits for them (Composer.Wait) once its run stops.

Builds: design 47 H2 H-A-480
This commit is contained in:
2026-11-22 16:12:10 +01:00
parent cb5eddeba8
commit a22769bbc6
4 changed files with 46 additions and 6 deletions
+22 -6
View File
@@ -197,6 +197,8 @@ type Composer struct {
AlsoEntriesAskAgain func(ctx context.Context)
env Env
// watchers counts the goroutines Watch started that end with its ctx (its loop and its hearers), for Wait (H-A-480).
watchers sync.WaitGroup
mu sync.Mutex
wants map[string]meshwants.WantsByWantNodeModuleValue // by module, the node's own under agent.NodeModule
assignments map[string]meshmoduleassigner.Assignments
@@ -582,12 +584,16 @@ func (c *Composer) Watch(ctx context.Context, _ string) (<-chan agent.Update, er
}(i, ch)
}
if c.env.Hear != nil {
go c.hearCatalogRevisions(ctx, func() {
select {
case merged <- tagged{in: -1, ok: true}:
case <-ctx.Done():
}
})
c.watchers.Add(1)
go func() {
defer c.watchers.Done()
c.hearCatalogRevisions(ctx, func() {
select {
case merged <- tagged{in: -1, ok: true}:
case <-ctx.Done():
}
})
}()
heard, stop, err := c.env.Hear(VaultSecretChanged)
if err != nil {
return nil, fmt.Errorf("the node composes again when a secret changes, and cannot hear the vault say so: %w", err)
@@ -604,7 +610,9 @@ func (c *Composer) Watch(ctx context.Context, _ string) (<-chan agent.Update, er
heard <-chan []byte
stop func()
}{{heard, stop}, {changed, stopChanged}} {
c.watchers.Add(1)
go func() {
defer c.watchers.Done()
defer h.stop()
for {
select {
@@ -625,7 +633,9 @@ func (c *Composer) Watch(ctx context.Context, _ string) (<-chan agent.Update, er
}
}
if c.env.SeatListChanged != nil {
c.watchers.Add(1)
go func() {
defer c.watchers.Done()
for {
select {
case <-ctx.Done():
@@ -645,7 +655,9 @@ func (c *Composer) Watch(ctx context.Context, _ string) (<-chan agent.Update, er
}
out := make(chan agent.Update, 64)
c.watching.Store(true)
c.watchers.Add(1)
go func() {
defer c.watchers.Done()
defer close(out)
defer c.watching.Store(false)
caught := make([]bool, len(ins))
@@ -761,6 +773,10 @@ func (c *Composer) Watch(ctx context.Context, _ string) (<-chan agent.Update, er
return out, nil
}
// Wait waits until the loop and the hearers Watch started have ended, each once its ctx ended: the node agent's stop waits for it,
// so the composer says nothing once its run is over (design 47 H2 H-A-480).
func (c *Composer) Wait() { c.watchers.Wait() }
// hearCatalogRevisions hears the seat mesh-catalog's event catalog-revision: each one asks again the entries whose ask failed (H-A-110), clears the backoffs of the trunk builds the
// catalog gave none of and wakes a pass (A-487a). A wake-up only, the backoff bounds the asks without it: a subscription refused
// is said once with its subject and error (principle 3), the composer goes on composing, and the subscription is tried again on