Skip to content

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

Merged
adinauer merged 4 commits into
mainfrom
feat/fix-thread-creation-by-timer
Jun 23, 2022
Merged

Fix thread leak due to Timer being created and never cancelled#2131
adinauer merged 4 commits into
mainfrom
feat/fix-thread-creation-by-timer

Conversation

@adinauer

@adinauer adinauer commented Jun 23, 2022

Copy link
Copy Markdown
Member

📜 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
@adinauer
adinauer requested a review from marandaneto June 23, 2022 13:54
@codecov-commenter

Copy link
Copy Markdown

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.

Comment thread sentry/src/main/java/io/sentry/SentryTracer.java Outdated
Comment thread sentry/src/main/java/io/sentry/SentryTracer.java Outdated
this.hub = hub;
this.currentDateProvider = currentDateProvider;
if (enableSessionTracking) {
timer = new Timer(true);

Copy link
Copy Markdown
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

@adinauer
adinauer requested review from bruno-garcia and romtsn June 23, 2022 14:46

@romtsn romtsn left a comment

Copy link
Copy Markdown
Member

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