Skip to content

Commit 1e5fa6d

Browse files
authored
Merge pull request #1120 from newrelic/dev
Release 12.1
2 parents 2f79c48 + 04c44e4 commit 1e5fa6d

37 files changed

+1445
-51
lines changed

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ GCOV ?= gcov
1010
SHELL = /bin/bash
1111
GCOVR ?= gcovr
1212
GIT ?= git
13+
# make sure go toolchain defined in daemon/go.mod is always used
14+
GOTOOLCHAIN=auto
1315

1416
include make/config.mk
1517
include make/vendor.mk
@@ -165,9 +167,17 @@ agent-valgrind: agent/Makefile
165167
# Configure the target directory for go install
166168
export GOBIN=$(CURDIR)/bin
167169

170+
.PHONY: daemon-golang-verify
171+
daemon-golang-verify:
172+
@golang_in_binary=$$(go version -m bin/daemon | awk '/^bin\/daemon/ {print $$2;}') \
173+
&& golang_from_toolchain=$$(awk '/^toolchain/ {print $$2;}' daemon/go.mod) \
174+
&& [ "$$golang_in_binary" = "$$golang_from_toolchain" ] && echo "daemon built using: $$golang_from_toolchain" \
175+
|| { echo "ERROR: daemon built using go: $$golang_in_binary, required: $$golang_from_toolchain"; exit 1; }
176+
168177
.PHONY: daemon
169178
daemon:
170179
$(MAKE) -C daemon
180+
$(MAKE) daemon-golang-verify
171181

172182
.PHONY: daemon_race
173183
daemon_race:

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12.0.0
1+
12.1.0

agent/fw_cakephp.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,12 @@ void nr_cakephp_enable(TSRMLS_D) {
173173
nr_php_wrap_user_function(
174174
NR_PSTR("Cake\\Controller\\Controller::invokeAction"),
175175
nr_cakephp_name_the_wt_4);
176-
nr_php_wrap_user_function(
177-
NR_PSTR(
178-
"Cake\\Error\\Middleware\\ErrorHandlerMiddleware::handleException"),
179-
nr_cakephp_error_handler_wrapper);
176+
if (!NRINI(ignore_framework_error_exception_handler)) {
177+
nr_php_wrap_user_function(
178+
NR_PSTR(
179+
"Cake\\Error\\Middleware\\ErrorHandlerMiddleware::handleException"),
180+
nr_cakephp_error_handler_wrapper);
181+
}
180182
nr_txn_suggest_package_supportability_metric(NRPRG(txn), PHP_PACKAGE_NAME,
181183
PHP_PACKAGE_VERSION_UNKNOWN);
182184
}

agent/fw_drupal8.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -898,14 +898,16 @@ void nr_drupal8_enable(TSRMLS_D) {
898898
/*
899899
* Log exceptions without further handling.
900900
*/
901-
nr_php_wrap_user_function(NR_PSTR("Drupal\\Core\\EventSubscriber\\ExceptionLoggingSubscriber::onException"),
902-
nr_drupal_exception);
901+
if (!NRINI(ignore_framework_error_exception_handler)) {
902+
nr_php_wrap_user_function(NR_PSTR("Drupal\\Core\\EventSubscriber\\ExceptionLoggingSubscriber::onException"),
903+
nr_drupal_exception);
903904

904-
/*
905-
* Last-chance handler for exceptions: the final exception subscriber.
906-
*/
907-
nr_php_wrap_user_function(NR_PSTR("Drupal\\Core\\EventSubscriber\\FinalExceptionSubscriber::onException"),
908-
nr_drupal_exception);
905+
/*
906+
* Last-chance handler for exceptions: the final exception subscriber.
907+
*/
908+
nr_php_wrap_user_function(NR_PSTR("Drupal\\Core\\EventSubscriber\\FinalExceptionSubscriber::onException"),
909+
nr_drupal_exception);
910+
}
909911
// clang-format on
910912

911913
/*

agent/fw_laravel.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -865,19 +865,21 @@ NR_PHP_WRAPPER(nr_laravel5_application_boot) {
865865
* to sensibly name transactions when an exception is thrown during routing
866866
* and also to record the error.
867867
*/
868-
exception_handler = nr_php_call_offsetGet(
869-
this_var, "Illuminate\\Contracts\\Debug\\ExceptionHandler" TSRMLS_CC);
870-
if (nr_php_is_zval_valid_object(exception_handler)) {
871-
nr_laravel_add_callback_method(Z_OBJCE_P(exception_handler),
872-
NR_PSTR("render"),
873-
nr_laravel5_exception_render TSRMLS_CC);
874-
875-
nr_laravel_add_callback_method(Z_OBJCE_P(exception_handler),
876-
NR_PSTR("report"),
877-
nr_laravel5_exception_report TSRMLS_CC);
878-
} else {
879-
nrl_verbosedebug(NRL_FRAMEWORK, "%s: cannot get exception handler",
880-
__func__);
868+
if (!NRINI(ignore_framework_error_exception_handler)) {
869+
exception_handler = nr_php_call_offsetGet(
870+
this_var, "Illuminate\\Contracts\\Debug\\ExceptionHandler" TSRMLS_CC);
871+
if (nr_php_is_zval_valid_object(exception_handler)) {
872+
nr_laravel_add_callback_method(Z_OBJCE_P(exception_handler),
873+
NR_PSTR("render"),
874+
nr_laravel5_exception_render TSRMLS_CC);
875+
876+
nr_laravel_add_callback_method(Z_OBJCE_P(exception_handler),
877+
NR_PSTR("report"),
878+
nr_laravel5_exception_report TSRMLS_CC);
879+
} else {
880+
nrl_verbosedebug(NRL_FRAMEWORK, "%s: cannot get exception handler",
881+
__func__);
882+
}
881883
}
882884

883885
end:

agent/fw_lumen.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,18 @@ void nr_lumen_enable(TSRMLS_D) {
218218
nr_php_wrap_user_function(
219219
NR_PSTR("Laravel\\Lumen\\Application::handleFoundRoute"),
220220
nr_lumen_handle_found_route TSRMLS_CC);
221+
if (!NRINI(ignore_framework_error_exception_handler)) {
221222
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO \
222223
&& !defined OVERWRITE_ZEND_EXECUTE_DATA
223-
nr_php_wrap_user_function_before_after_clean(
224-
NR_PSTR("Laravel\\Lumen\\Application::sendExceptionToHandler"),
225-
nr_lumen_exception, NULL, NULL);
224+
nr_php_wrap_user_function_before_after_clean(
225+
NR_PSTR("Laravel\\Lumen\\Application::sendExceptionToHandler"),
226+
nr_lumen_exception, NULL, NULL);
226227
#else
227-
nr_php_wrap_user_function(
228-
NR_PSTR("Laravel\\Lumen\\Application::sendExceptionToHandler"),
229-
nr_lumen_exception TSRMLS_CC);
228+
nr_php_wrap_user_function(
229+
NR_PSTR("Laravel\\Lumen\\Application::sendExceptionToHandler"),
230+
nr_lumen_exception TSRMLS_CC);
230231
#endif
232+
}
231233

232234
if (NRINI(vulnerability_management_package_detection_enabled)) {
233235
nr_txn_add_php_package(NRPRG(txn), PHP_PACKAGE_NAME,

agent/fw_symfony4.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,21 @@ void nr_symfony4_enable(TSRMLS_D) {
250250
* nr_txn_record_error and pass the exception message. Now we get errors in
251251
* the error analytics page.
252252
*/
253-
nr_php_wrap_user_function(
254-
NR_PSTR("Symfony\\Component\\HttpKernel\\"
255-
"EventListener\\ExceptionListener::onKernelException"),
256-
nr_symfony4_exception TSRMLS_CC);
253+
if (!NRINI(ignore_framework_error_exception_handler)) {
254+
nr_php_wrap_user_function(
255+
NR_PSTR("Symfony\\Component\\HttpKernel\\"
256+
"EventListener\\ExceptionListener::onKernelException"),
257+
nr_symfony4_exception TSRMLS_CC);
257258

258-
/*
259-
* In Symfony 5 listener that catch errors was changed to ErrorListener,
260-
* we try to hook into it
261-
*/
262-
nr_php_wrap_user_function(
263-
NR_PSTR("Symfony\\Component\\HttpKernel\\"
264-
"EventListener\\ErrorListener::onKernelException"),
265-
nr_symfony4_exception TSRMLS_CC);
259+
/*
260+
* In Symfony 5 listener that catch errors was changed to ErrorListener,
261+
* we try to hook into it
262+
*/
263+
nr_php_wrap_user_function(
264+
NR_PSTR("Symfony\\Component\\HttpKernel\\"
265+
"EventListener\\ErrorListener::onKernelException"),
266+
nr_symfony4_exception TSRMLS_CC);
267+
}
266268

267269
/*
268270
* Listen for Symfony commands so we can name those appropriately.

agent/fw_yii.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,10 @@ void nr_yii2_enable(TSRMLS_D) {
219219
* allowing default PHP error handler to be intercepted by the NewRelic agent
220220
* implementation.
221221
*/
222-
nr_php_wrap_user_function(NR_PSTR("yii\\base\\ErrorHandler::logException"),
223-
nr_yii2_error_handler_wrapper TSRMLS_CC);
222+
if (!NRINI(ignore_framework_error_exception_handler)) {
223+
nr_php_wrap_user_function(NR_PSTR("yii\\base\\ErrorHandler::logException"),
224+
nr_yii2_error_handler_wrapper TSRMLS_CC);
225+
}
224226
#endif
225227

226228
if (NRINI(vulnerability_management_package_detection_enabled)) {

agent/php_mysqli.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,3 +688,28 @@ const char* nr_php_mysqli_strip_persistent_prefix(const char* host) {
688688

689689
return host;
690690
}
691+
692+
void nr_php_mysqli_rshutdown() {
693+
/*
694+
* This frees mysqli metadata stored in the transaction.
695+
*
696+
* `mysqli_queries` contains duplicates of zvals. If
697+
* `nr_php_txn_end` is called from the post-deactivate callback, request
698+
* shutdown functions have already been called; and the Zend VM has already
699+
* forcefully freed all dangling zvals that are not referenced by the global
700+
* scope (regardless of their reference count), thus leaving the zvals stored
701+
* in the mysqli_queries metadata in an "undefined" state. Consequently,
702+
* freeing the zvals in `nr_php_txn_end` at this stage can result in undefined
703+
* behavior.
704+
*
705+
* Calling this function during the RSHUTDOWN phase ensures that the zvals in
706+
* `mysqli_queries` are cleaned up before Zend winds down the VM and
707+
* forcefully frees zvals.
708+
*
709+
* If `nr_php_txn_end` is called outside the post-deactivate callback,
710+
* it frees `mysqli_queries` by itself.
711+
*/
712+
if (nrlikely(NRPRG(txn))) {
713+
nr_hashmap_destroy(&NRTXNGLOBAL(mysqli_queries));
714+
}
715+
}

agent/php_mysqli.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,10 @@ extern nr_datastore_instance_t* nr_php_mysqli_retrieve_datastore_instance(
163163
extern void nr_php_mysqli_remove_datastore_instance(
164164
const zval* mysqli_obj TSRMLS_DC);
165165

166+
/*
167+
* Purpose : Frees reference incremented, transaction global zvals
168+
* that must be cleaned up prior to postdeactivate
169+
*/
170+
extern void nr_php_mysqli_rshutdown();
171+
166172
#endif /* PHP_MYSQLI_HDR */

0 commit comments

Comments
 (0)