derp: remove stats goroutine, use a timer

Without changing behaviour, don't create a goroutine per connection that
sits and sleeps, but rather use a timer that wakes up and gathers
statistics on a regular basis.

Fixes #12127

Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
Change-Id: Ibc486447e403070bdc3c2cd8ae340e7d02854f21
This commit is contained in:
Andrew Dunham
2024-05-14 12:28:01 -04:00
parent 7ef2f72135
commit c6d42b1093
3 changed files with 28 additions and 23 deletions
+2 -1
View File
@@ -776,7 +776,6 @@ func (c *sclient) run(ctx context.Context) error {
var grp errgroup.Group
sendCtx, cancelSender := context.WithCancel(ctx)
grp.Go(func() error { return c.sendLoop(sendCtx) })
grp.Go(func() error { return c.statsLoop(sendCtx) })
defer func() {
cancelSender()
if err := grp.Wait(); err != nil && !c.s.isClosed() {
@@ -788,6 +787,8 @@ func (c *sclient) run(ctx context.Context) error {
}
}()
c.startStatsLoop(sendCtx)
for {
ft, fl, err := readFrameHeader(c.br)
c.debugLogf("read frame type %d len %d err %v", ft, fl, err)