streamJanitorLoop periodically reaps idle chat stream states whose grace period has expired. It is the backstop for the grace-window early-return in cleanupStreamIfIdle; without it, a subscriber that detaches inside grace (the common enterprise relay-drain case, relayDrainTimeout = 200ms vs. 5s grac
(ctx context.Context)
| 4750 | // detaches inside grace (the common enterprise relay-drain case, |
| 4751 | // relayDrainTimeout = 200ms vs. 5s grace) pins the state forever. |
| 4752 | func (p *Server) streamJanitorLoop(ctx context.Context) { |
| 4753 | ticker := p.clock.NewTicker(streamJanitorInterval, "chatd", "stream-janitor") |
| 4754 | defer ticker.Stop() |
| 4755 | for { |
| 4756 | select { |
| 4757 | case <-ctx.Done(): |
| 4758 | return |
| 4759 | case <-ticker.C: |
| 4760 | p.safeSweepIdleStreams(ctx) |
| 4761 | } |
| 4762 | } |
| 4763 | } |
| 4764 | |
| 4765 | // safeSweepIdleStreams runs sweepIdleStreams under a panic recovery |
| 4766 | // so an unexpected panic in the sweep cannot kill the janitor |
no test coverage detected