-
Notifications
You must be signed in to change notification settings - Fork 69
fix(agent): Don't skip arguments when calling mysqli::real_connect #972
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
Conversation
@kovshenin Thank you for engaging and your interest in improving New Relic’s PHP instrumentation! Could you update this PR and set dev as the base branch? Here’s a picture how to do it after you click on the ‘Edit’ button next to PR’s title: |
7a76cd5
to
d2782bd
Compare
@lavarou changed and rebased. |
Allow connecting to mysqldb via socket.
Test slowsql functionality when mysqldb is accessed via socket.
When one of the arguments in nr_php_mysqli_link_real_connect is null, the entire argument is skipped. This causes a fatal error when attempting to connect to a database through a Unix socket, without specifying a port number. This change ensures all arguments are passed on to real_connect in the correct order, including any nulls.
@kovshenin Thank you for your contribution! We looked at the suggested changes and enhanced our tests to test it out - see #976. This PR indeed addresses the issue from the description, and the tests added in #976 pass. However it caused a few existing tests to fail:
These test failures will need us to further investigate and allocate time to resolve. If you wish to investigate the failures locally, you can use the containerized development environment to build the agent and run the tests locally (only the New Relic license key is required). |
The correct default for the $flags argument is 0, not null. Passing a null causes a warning.
d2782bd
to
e937403
Compare
Thanks for taking a look @lavarou! I totally missed the fact that the $flags argument defaults to 0 and not null. I believe I've addressed this in e937403. However I am seeing some other test failures around jit and some remote requests (X-Newrelic-App-Data, X-NewRelic-ID headers) which I don't think are related, or perhaps my license key is misconfigured. |
Hmm, I see some of the explain tests failed again. I'm having a hard time reproducing these in my environment. Here's what I'm running from within a dev-shell:
And I get:
In all PHP versions. I'd appreciate some clues as I am very new to this :) Thanks! |
Hi @kovshenin It looks like part of the problem is that argc in the function previously only incremented for non-null parameters, so it's throwing the count off when we are using it in if statements. argc was basically being used for both parameter count and to track non-null settings. Please check out the changes added #976 to and see if you agree. These change passed all tests. |
Thanks for the explanation @zsistla, that makes a lot of sense, I thinks this will work! I left a couple of comments on the PR. |
@kovshenin How do you start the dev-shell for different PHPs? What is the output of |
@lavarou I just run Did I run all my tests under 8.3 only? Does |
Closing this PR - it was incorporated into #976 and released in 11.3. Thanks again for your contribution! |
Hi @kovshenin! I assume you must have used
Yes.
Yes.
No worries! We appreciate your attempt to use containerized development environment and this feedback is very valuable! We'll try to make containerized development environment more user friendly - see #977. |
Hi @lavarou yeah it makes sense now, also explains why my tests weren't failing 🤣 I was actually pleasantly surprised with the containerized dev environment, it felt very neat and I had most things working without having to jump through hoops with a million dependencies on my local system. Having the ability to set a PHP version for the shell would be a great addition to that, thanks for working on it! |
When one of the arguments in
nr_php_mysqli_link_real_connect
isnull
, the entire argument is skipped. This causes a fatal error when attempting to connect to a database through a Unix socket, without specifying a port number.Here are two sample connection strings:
If you run a slow query against these, one that would trigger the additional EXPLAIN routine, the agent will fall into the
nr_php_mysqli_link_duplicate
routine, and eventually intonr_php_mysqli_link_real_connect
where it callsmysqli::real_connect
. The first link's arguments will be accurate:However, the second link will choke on the (lack of) port:
The
mysqli::real_connect
method expects the fifth parameter to be an integer port number, but is going to get a string instead. With recent versions of PHP this fails with a fatal error:The proposed change ensures all arguments are passed on to real_connect in the correct order, including any nulls.
Somewhat related to #881 I guess.