Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Memory leaks caused by time.After #913

Open
biningo opened this issue Sep 3, 2024 · 0 comments · May be fixed by #914
Open

[BUG] Memory leaks caused by time.After #913

biningo opened this issue Sep 3, 2024 · 0 comments · May be fixed by #914
Assignees
Labels
bug Something isn't working

Comments

@biningo
Copy link

biningo commented Sep 3, 2024

Describe the bug
timer.After() creates a new timer object each time it is called. Which can cause a memory leak in the for loop.

asynq/subscriber.go

Lines 61 to 74 in d04888e

for {
pubsub, err = s.broker.CancelationPubSub()
if err != nil {
s.logger.Errorf("cannot subscribe to cancelation channel: %v", err)
select {
case <-time.After(s.retryTimeout):
continue
case <-s.done:
s.logger.Debug("Subscriber done")
return
}
}
break
}

asynq/syncer.go

Lines 60 to 85 in d04888e

for {
select {
case <-s.done:
// Try sync one last time before shutting down.
for _, req := range requests {
if err := req.fn(); err != nil {
s.logger.Error(req.errMsg)
}
}
s.logger.Debug("Syncer done")
return
case req := <-s.requestsCh:
requests = append(requests, req)
case <-time.After(s.interval):
var temp []*syncRequest
for _, req := range requests {
if req.deadline.Before(time.Now()) {
continue // drop stale request
}
if err := req.fn(); err != nil {
temp = append(temp, req)
}
}
requests = temp
}
}

To Reproduce

Expected behavior
Creating the timer object before the for loop.

Screenshots

Environment (please complete the following information):

  • OS: Linux
  • Version of asynq package v0.24.1

Additional context

@biningo biningo added the bug Something isn't working label Sep 3, 2024
@biningo biningo linked a pull request Sep 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
2 participants