Skip to content

Commit ebbf556

Browse files
committed
Exec integration: remove usage of dynamic property
1 parent 4820fea commit ebbf556

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

ext/integrations/exec_integration.c

+1-15
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,7 @@ static void dd_proc_wrapper_rsrc_dtor(zend_resource *rsrc) {
118118
ddtrace_span_data *span_data = OBJ_SPANDATA(proc_span->span);
119119

120120
if (span_data->duration == 0) {
121-
// if we reaped, the proc handle destructor will set
122-
// FG(pclose_ret) to -1, causing proc_close to return -1, so we
123-
// must signal that we have to override the return value in the post
124-
// hook of proc_close
125-
bool did_reap = dd_waitpid(span_data, proc_span->child);
126-
if (did_reap) {
127-
// set a dynamic property on the span
128-
#if PHP_VERSION_ID < 80000
129-
zval zobj;
130-
ZVAL_OBJ(&zobj, proc_span->span);
131-
zend_update_property_bool(ddtrace_ce_span_data, &zobj, ZEND_STRL("overrideRetval"), 1);
132-
#else
133-
zend_update_property_bool(ddtrace_ce_span_data, proc_span->span, ZEND_STRL("overrideRetval"), 1);
134-
#endif
135-
}
121+
(void)dd_waitpid(span_data, proc_span->child);
136122

137123
dd_trace_stop_span_time(span_data);
138124
ddtrace_close_span_restore_stack(span_data);

src/Integrations/Integrations/Exec/ExecIntegration.php

+16-5
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,21 @@ static function (HookData $hook) {
166166
return;
167167
}
168168

169-
// the span must be retrieved from the resource because by the time
170-
// the post hook runs, the resource has already been destroyed
171-
$hook->data = proc_get_span($hook->args[0]);
169+
// the span must be stored in $hook because by the time the post
170+
//hook runs, the resource has already been destroyed
171+
$span = proc_get_span($hook->args[0]);
172+
if (!$span) {
173+
return;
174+
}
175+
// must match condition in dd_proc_wrapper_rsrc_dtor before
176+
// calling dd_waitpid()
177+
if ($span->getDuration() != 0) {
178+
return;
179+
}
180+
// if we get here, we will call waitpid() in the resource
181+
// destructor and very likely reap the process, resulting in
182+
// proc_close() returning -1
183+
$hook->data = $span;
172184
},
173185
static function (HookData $hook) {
174186
/** @var SpanData $span */
@@ -177,9 +189,8 @@ static function (HookData $hook) {
177189
return;
178190
}
179191

180-
if (isset($span->overrideRetval) && key_exists(Tag::EXEC_EXIT_CODE, $span->meta)) {
192+
if ($hook->returned === -1 && isset($span->meta[Tag::EXEC_EXIT_CODE])) {
181193
$hook->overrideReturnValue($span->meta[Tag::EXEC_EXIT_CODE]);
182-
unset($span->overrideRetval);
183194
}
184195
}
185196
);

0 commit comments

Comments
 (0)