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

Fix thread leak due to Timer being created and never cancelled #2131

Merged
merged 4 commits into from Jun 23, 2022

Conversation

adinauer
Copy link
Member

@adinauer adinauer commented Jun 23, 2022

📜 Description

Timer was created for every transaction which caused a new thread to be spawned each time. With this PR the Timer is only created in SentryTracer if idleTimeout is set there. When the transaction is finished, the timer is cancelled.

💡 Motivation and Context

Fixes #2115

💚 How did you test it?

  • Spring Boot App with transactions, before PR threads would be spawned, with code from PR no timer threads are spawned

📝 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • No breaking changes

🔮 Next steps

@adinauer adinauer requested a review from romtsn as a code owner June 23, 2022 13:42
@codecov-commenter
Copy link

Codecov Report

Merging #2131 (cd9933c) into main (b5ef9c5) will increase coverage by 0.00%.
The diff coverage is 83.33%.

❗ Current head cd9933c differs from pull request most recent head 4c5db65. Consider uploading reports for the commit 4c5db65 to get more accurate results

@@            Coverage Diff            @@
##               main    #2131   +/-   ##
=========================================
  Coverage     80.93%   80.94%           
- Complexity     3254     3257    +3     
=========================================
  Files           231      231           
  Lines         11951    11957    +6     
  Branches       1586     1588    +2     
=========================================
+ Hits           9673     9679    +6     
  Misses         1698     1698           
  Partials        580      580           
Impacted Files Coverage Δ
...entry/src/main/java/io/sentry/NoOpTransaction.java 25.80% <0.00%> (ø)
sentry/src/main/java/io/sentry/SentryTracer.java 91.42% <88.23%> (+0.25%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b5ef9c5...4c5db65. Read the comment docs.

@@ -54,6 +55,11 @@ final class LifecycleWatcher implements DefaultLifecycleObserver {
this.enableAppLifecycleBreadcrumbs = enableAppLifecycleBreadcrumbs;
this.hub = hub;
this.currentDateProvider = currentDateProvider;
if (enableSessionTracking) {
timer = new Timer(true);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure where we could call cancel on the timer here

Copy link
Member

@romtsn romtsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Android briefly, looked good, thanks for doing this!

@adinauer adinauer merged commit 5127b6e into main Jun 23, 2022
@adinauer adinauer deleted the feat/fix-thread-creation-by-timer branch June 23, 2022 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lazily create Timer to avoid creating not needed threads
4 participants