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

Bugfix Thread instrumentation continuing to use finished transactions on other threads #1969

Merged
merged 9 commits into from
Apr 26, 2023

Conversation

tannalynn
Copy link
Contributor

@tannalynn tannalynn commented Apr 25, 2023

This fixes a bug where the agent would continue to record segments on transactions that were already finished in another thread. This would lead to increased memory usage over time because the agent would continue to copy over the finished transaction as the still current transaction in the thread instrumentation, causing the agent to think it was still supposed to continue recording data on the actually finished transaction. Now the agent will check the finished state of a transaction before using it when a new thread is spawned.
Additionally, if a transaction reaches the segment limit but the transaction is actually already finished on some other thread, the state will now reset, preventing future segments from being created and a supportability metric will be recorded.

#1936

@tannalynn tannalynn marked this pull request as ready for review April 25, 2023 23:12
@github-actions
Copy link
Contributor

SimpleCov Report

Coverage Threshold
Line 93.97% 93%
Branch 85.48% 85%

Copy link
Contributor

@fallwith fallwith left a comment

Choose a reason for hiding this comment

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

Memory copying for new threads can be tricky. I'm very glad to see you were able to get this addressed in such a clear way that doesn't risk adverse side effects.

@@ -29,6 +29,12 @@ def add_segment(segment, parent = nil)
else
segment.record_on_finish = true
::NewRelic::Agent.logger.debug("Segment limit of #{segment_limit} reached, ceasing collection.")

if finished?
::NewRelic::Agent.logger.debug("Transaction #{best_name} has finished but segments still being created, resetting state.")
Copy link
Contributor

Choose a reason for hiding this comment

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

This new module code make use of a method, best_name, that doesn't exist in the module, so the code can only be used by an instance of the Transaction class. Seeing as the Transaction class is the only consumer (includer) of this Tracing module, this is probably ok.

@tannalynn tannalynn merged commit 6c78a25 into dev Apr 26, 2023
kaylareopelle added a commit that referenced this pull request May 1, 2023
The NewRelic::Agent::PipeChannelManagerTest has two cases
failing on Ruby 2.5.9 and Rails 6.0/6.1:
#test_listener_merges_error_events, #test_listener_merges_error_traces

These tests started failing after PR#1969 was merged:
#1969

The tests are now skipped in the specific conditions where they
intermittently fail
@tannalynn tannalynn deleted the thread_instrumentation_no_txn_if_finished branch June 23, 2023 19:38
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.

3 participants