Closed kshnurov closed 2 years ago
hello @kshnurov I've been unable to reproduce this issue using
newrelic_rpm 8.2.0
Rails 6.1.4.1
Ruby 2.7.4
MySQL 5.7
mysql2 0.5.3
Do you have more information about this issue? How did you arrive at the ruby agent as being the source of this issue? Does this error occur when the ruby agent is disabled?
I searched the code in the ruby agent and I'm not seeing the method new_with_args
used anywhere, so it's not clear to me how the agent may be causing this error. I'm not seeing anything in the stack trace that obviously points to new relic being related to the issue either, other than the lines near the bottom that shows our instrumentation is wrapping these calls to active record.
If you would be so kind as to provide more details about how new relic is related to this issue and how to reproduce it, that would be helpful, thank you.
Hello @kshnurov, Thanks for submitting the issue within our repository. Our team cannot reproduce the problem based on the provided information. It will help us figure out if this is an issue with our agent if you could do the following test as suggested by @tannalynn. If you have an environment that you can run without the New Relic agent, could you remove the agent and see if the problem persists?
We plan to close this issue in a few days because, at this time, we are unable to proceed without more information.
Hi @angelatan2 @tannalynn, sorry for the delay.
The reason I though this is related to newrelic is that I got thousands of similar errors after upgrading from 7.2 to 8.1, which had distributed tracing on by default, and disabling distributed tracing fixed most of them.
There's an issue that was fixed in 8.2 https://github.com/newrelic/newrelic-ruby-agent/issues/801, but it's about object being nil
, not some random stuff which looks like a memory leak.
Unfortunately, I am unable to reproduce, it happens randomly, rarely and only in production, with many parallel Puma processes. Can't turn the agent off for too long.
new_with_args
is a mysql2 gem method, which is called when an ActiveRecord query has failed. Since newrelic prepends ActiveRecord methods and tracks errors I though this might be related, though I don't know the ruby agent code well enough to see how it could be the reason. Maybe you have an idea?
Hi @kshnurov! Thanks for your additional context. My apologies for our subsequent delay.
This doesn't seem like it is related to the agent. We do not instrument the mysql2 gem directly. For ActiveRecord, we prepend calls to its core methods, in this example save!
which gets called by create!
. Our instrumentation then accesses some of the variables to create a metric. I can't see a code path within our instrumentation that would cause new_with_args
to be raised.
If you'd like to take a closer look at our instrumentation of ActiveRecord, I recommend reviewing: lib/new_relic/agent/instrumentation/active_record_prepend.rb
Hi @kaylareopelle. Well, I've digged through the mysql2 code once again, and I've found the issue. It's not related to the newrelic, it's about GC in Ruby 2.7+. Sorry for bothering you.
Description
With Ruby 2.7+ mysql queries that should fail with ActiveRecord::RecordNotUnique produce ActiveRecord::StatementInvalid
NoMethodError: undefined method ``new_with_args'
, and the calling objects are weird. All fails happen in the same place that has nothing to do with these objects:Stacktrace
Steps to Reproduce
Your Environment
newrelic_rpm 8.2.0 Rails 6.1.4.1 Ruby 2.7 MySQL 5.7