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] - Potential Memory Leak Due to Timer Creation in AfterFunc and selectExecJobsOutForRescheduling #777

Open
hayotbisonai opened this issue Sep 17, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@hayotbisonai
Copy link
Contributor

Describe the bug

I've noticed a potential memory issue related to the use of timers and goroutines in the AfterFunc implementation in the clockwork package and the job rescheduling process in the scheduler. When profiling the application, I observed significant memory consumption, particularly related to time.goFunc and goroutines created by AfterFunc.

Key points:

  • The AfterFunc call creates a new goroutine each time a timer is set, and this can lead to many goroutines being created and left hanging if they are not stopped or properly handled.
  • The frequent scheduling and rescheduling of jobs in selectExecJobsOutForRescheduling might contribute to the problem due to timer and goroutine buildup.

Profile Data:

Showing nodes accounting for 239.24MB, 76.13% of 314.25MB total
Dropped 126 nodes (cum <= 1.57MB)
Showing top 10 nodes out of 107
      flat  flat%   sum%        cum   cum%
   79.66MB 25.35% 25.35%    79.66MB 25.35%  time.goFunc
   31.43MB 10.00% 35.35%    31.43MB 10.00%  github.com/go-co-op/gocron/v2.(*scheduler).selectNewJob
   31.01MB  9.87% 45.22%    31.01MB  9.87%  runtime.malg
   21.50MB  6.84% 52.06%    34.30MB 10.92%  context.withCancel (inline)
   19.01MB  6.05% 58.11%    21.05MB  6.70%  github.com/go-co-op/gocron/v2.(*scheduler).selectExecJobsOutForRescheduling

As seen, time.goFunc and the scheduling-related functions are taking a substantial amount of memory and keeps growing

To Reproduce

Steps to reproduce the behavior:

Version

Expected behavior

Additional context

@hayotbisonai hayotbisonai added the bug Something isn't working label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant