Tool runner bus: long-lived loops read their settings once, as they start
A hearing's loops, SeatTake's heartbeat and followGrants' retry loop outlive the call that started them and read the package's settings on every turn; a test that sets a setting back as it ends then raced the loop (the race detector: streams_test.go:232's cleanup write of RebindEvery against the rebind loop's read, in TestAConsumerNamedBeforeItExistsIsBoundOnceItDoes at -count=30). Each loop now takes RebindEvery, NakDelay, EventHeartbeat, WorkHeartbeat, GrantsRetry, GrantsRetryMost, GrantsPatience and StateTimeout once, as consumes already took IdleHeartbeat and its tick hook. Builds: design 47 H H-A-363 (fix-a-bug-met-twice: a goroutine outliving its settings)
This commit is contained in:
@@ -279,6 +279,8 @@ func (c *Conn) SeatTake(module, consumer string, deliver func(Work) error) (func
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("binding %s's worker %s on %s: %w", module, w.Consumer, w.Stream, err)
|
||||
}
|
||||
// Read once, as the take starts: its loop outlives SeatTake, and a test sets it back as it ends (design 47 H, H-A-363).
|
||||
heartbeat := WorkHeartbeat
|
||||
reading, err := bound.Consume(func(msg jetstream.Msg) {
|
||||
if !json.Valid(msg.Data()) {
|
||||
_ = msg.Term()
|
||||
@@ -292,7 +294,7 @@ func (c *Conn) SeatTake(module, consumer string, deliver func(Work) error) (func
|
||||
// that died, not one that is slow.
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
tick := time.NewTicker(WorkHeartbeat)
|
||||
tick := time.NewTicker(heartbeat)
|
||||
defer tick.Stop()
|
||||
for {
|
||||
select {
|
||||
|
||||
Reference in New Issue
Block a user