Skip to content

Commit b310ddd

Browse files
committed
Avoid resumption of unfinished hooks on PHP 7
Signed-off-by: Bob Weinand <[email protected]>
1 parent 67bc22b commit b310ddd

3 files changed

Lines changed: 8 additions & 9 deletions

File tree

tests/ext/bailout_double_hook_clear.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
--TEST--
22
Bailout during hook END should not cause double-clear of span (internal function)
3-
--SKIPIF--
4-
<?php if (PHP_VERSION_ID >= 80000) die('skip: PHP 7 only'); ?>
53
--FILE--
64
<?php
75

6+
DDTrace\trace_function('array_sum', [
7+
'posthook' => function(\DDTrace\SpanData $data, $args, $retval) {
8+
echo "Hook 0 END\n";
9+
}
10+
]);
11+
812
DDTrace\trace_function('array_sum', [
913
'prehook' => function (\DDTrace\SpanData $data, $args) {
1014
echo "HOOK 1 PRE\n";

zend_abstract_interface/hook/hook.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,12 +1112,6 @@ void zai_hook_finish(zend_execute_data *ex, zval *rv, zai_hook_memory_t *memory)
11121112
for (zai_hook_info *hook_start = memory->dynamic, *hook_info = hook_start + memory->hook_count - 1; hook_info >= hook_start; --hook_info) {
11131113
zai_hook_t *hook = hook_info->hook;
11141114

1115-
// if we propagate bailout during hook->end, we don't try to finish
1116-
// again in zai_interceptor_terminate_all_pending_observers
1117-
// This may even segfault due to too many calls to
1118-
// ddtrace_clear_execute_data_span
1119-
memory->hook_count--;
1120-
11211115
if (hook->end) {
11221116
hook->end(memory->invocation, ex, rv, hook->aux.data, (char *)memory->dynamic + hook_info->dynamic_offset);
11231117
}

zend_abstract_interface/interceptor/php7/interceptor.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,8 @@ static inline void zai_interceptor_execute_internal_impl(zend_execute_data *exec
506506
func->internal_function.handler(execute_data, return_value);
507507
}
508508

509-
zai_hook_finish(execute_data, return_value, &stored_frame_memory->hook_data);
509+
stored_frame_memory->implicit = true; // prevent double-finish on bailout
510+
zai_hook_finish(execute_data, return_value, &frame_memory.hook_data);
510511
zai_hook_memory_table_del(execute_data);
511512
} else {
512513
skip: ;

0 commit comments

Comments
 (0)