Skip to content

Commit

Permalink
fix go routines leak
Browse files Browse the repository at this point in the history
  • Loading branch information
vintikzzz committed Oct 30, 2024
1 parent d37ea78 commit 8429091
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/anacrolix/chansync v0.6.0 // indirect
github.com/anacrolix/log v0.16.0
github.com/anacrolix/sync v0.5.2 // indirect
github.com/aws/aws-sdk-go v1.44.163
github.com/bakins/logrus-middleware v0.0.0-20180426214643-ce4c6f8deb07
github.com/bakins/test-helpers v0.0.0-20141028124846-af83df64dc31 // indirect
github.com/dustin/go-humanize v1.0.1
Expand Down Expand Up @@ -55,6 +54,7 @@ require (
github.com/anacrolix/stm v0.5.0 // indirect
github.com/anacrolix/upnp v0.1.4 // indirect
github.com/anacrolix/utp v0.2.0 // indirect
github.com/aws/aws-sdk-go v1.44.163 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/benbjohnson/immutable v0.4.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
3 changes: 3 additions & 0 deletions server/services/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ func (s *Stat) StatStream(in *pb.StatRequest, stream pb.TorrentWebSeeder_StatStr
log.WithField("path", in.GetPath()).Info("sending stats completed")
}
return err
case <-time.After(30 * time.Minute):
log.WithField("path", in.GetPath()).Info("sending stats timeout")
return nil
case err := <-errCh:
if err != nil {
return status.Errorf(codes.Internal, "got error=%v", err)
Expand Down
9 changes: 7 additions & 2 deletions server/services/stat_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ func (s *StatWeb) Serve(w http.ResponseWriter, r *http.Request, h string, p stri
stream := NewStatStreamServer(ctx, ha, f)
ticker := time.NewTicker(10 * time.Second)
go func() {
for range ticker.C {
stream.Ping()
for {
select {
case <-ticker.C:
stream.Ping()
case <-ctx.Done():
return
}
}
}()
err := s.st.StatStream(&pb.StatRequest{Path: p}, stream)
Expand Down

0 comments on commit 8429091

Please sign in to comment.