opentelemetry-php icon indicating copy to clipboard operation
opentelemetry-php copied to clipboard

[opentelemetry-php-instrumentation] - [PHP82] OpenTelemetry + Blackfire extensions results with SegFault

Open gkawka opened this issue 3 years ago • 6 comments

Environment Working on docker on Linux, production is running on Kubernetes pods

Both ways to install Blackfire ext with opentelemetry-1.0.0beta5 extension result in Segmentation Fault

FROM php:8.2-fpm-alpine

RUN apk update

RUN apk add \
    autoconf \
    g++ \
    gcc \
    make \
    bash


RUN pecl install \
    opentelemetry-1.0.0beta5

RUN docker-php-ext-enable \
    opentelemetry

SHELL ["/bin/ash", "-eo", "pipefail", "-c"]

# Blackfire agent
RUN bash -c "$(curl -L https://installer.blackfire.io/installer.sh)"
# makes segmentation fault :(
RUN blackfire php:install
FROM php:8.2-fpm-alpine

RUN apk update

RUN apk add \
    autoconf \
    g++ \
    gcc \
    make \
    bash


RUN pecl install \
    opentelemetry-1.0.0beta5

RUN docker-php-ext-enable \
    opentelemetry

SHELL ["/bin/ash", "-eo", "pipefail", "-c"]

RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
    && architecture=$(uname -m) \
    && curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/alpine/$architecture/$version \
    && mkdir -p /tmp/blackfire \
    && tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
    && mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so \
    && printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8307\n" > $PHP_INI_DIR/conf.d/blackfire.ini \
    && rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz

Steps to reproduce

  1. build and run Dockerfile
  2. Run php -i

What is the expected behavior? Normal PHP behavoiur

What is the actual behavior?

/var/www/html # php -i
Segmentation fault (core dumped)

gkawka avatar Jun 06 '23 04:06 gkawka

We were discussing this in our TC meeting today - does this work with a docker image that isn't alpine?

bobstrecansky avatar Jun 07 '23 12:06 bobstrecansky

(We should expect it to work with Alpine, just trying to isolate problem areas)

bobstrecansky avatar Jun 07 '23 12:06 bobstrecansky

Hi, thanks for response. Tried Dockerfile from below but it doesn't manage to enable blackfire ext with such warning:

Step 5/7 : RUN docker-php-ext-enable blackfire
 ---> Running in 5cf069cb1267
Warning: PHP Startup: Unable to load dynamic library 'blackfire.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20220829/blackfire.so (libc.musl-x86_64.so.1: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20220829/blackfire.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20220829/blackfire.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Warning: PHP Startup: Unable to load dynamic library 'blackfire.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20220829/blackfire.so (libc.musl-x86_64.so.1: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20220829/blackfire.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20220829/blackfire.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
FROM php:8.2.6-fpm

RUN apt-get update

RUN apt-get install -y \
    autoconf \
    g++ \
    gcc \
    make \
    bash \
    musl-dev \
    sudo


RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
    && architecture=$(uname -m) \
    && curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/alpine/$architecture/$version \
    && mkdir -p /tmp/blackfire \
    && tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
    && mv /tmp/blackfire/blackfire-*.so  /usr/local/lib/php/extensions/no-debug-non-zts-20220829/blackfire.so \
    && printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8307\n" > $PHP_INI_DIR/conf.d/blackfire.ini \
    && rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz

RUN docker-php-ext-enable blackfire

RUN pecl install \
    opentelemetry-1.0.0beta5

RUN docker-php-ext-enable \
    opentelemetry

Also running blackfire installer fails with error cannot restart blackfire-agent service

gkawka avatar Jun 07 '23 12:06 gkawka

I was able to install opentelemetry + blackfire in alpine, and it segfaults just the same. I was able to get a bit of a backtrace from gdb, but blackfire would not install against a debug build of PHP for better backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x000056122b3707d9 in zend_hash_find ()
(gdb) bt
#0  0x000056122b3707d9 in zend_hash_find ()
open-telemetry/opentelemetry-php#1  0x000056122b370891 in zend_hash_find_ptr_lc ()
open-telemetry/opentelemetry-php#2  0x00007f1bc7c45b13 in find_observers (ht=<optimized out>, n=<optimized out>, pre_hooks=pre_hooks@entry=0x7ffd5f82e920, post_hooks=post_hooks@entry=0x7ffd5f82e958) at /tmp/pear/temp/opentelemetry/otel_observer.c:355
open-telemetry/opentelemetry-php#3  0x00007f1bc7c468ca in resolve_observer (execute_data=0x7f1bc7a127c0) at /tmp/pear/temp/opentelemetry/otel_observer.c:424
open-telemetry/opentelemetry-php#4  observer_fcall_init (execute_data=0x7f1bc7a127c0) at /tmp/pear/temp/opentelemetry/otel_observer.c:446
open-telemetry/opentelemetry-php#5  observer_fcall_init (execute_data=0x7f1bc7a127c0) at /tmp/pear/temp/opentelemetry/otel_observer.c:441
open-telemetry/opentelemetry-php#6  0x000056122b3f4ab7 in ?? ()
open-telemetry/opentelemetry-php#7  0x000056122b03abce in ?? ()
open-telemetry/opentelemetry-php#8  0x000056122b03b59a in ?? ()
open-telemetry/opentelemetry-php#9  0x00007f1bc7c73aea in ?? () from /usr/local/lib/php/extensions/no-debug-non-zts-20220829/blackfire.so
open-telemetry/opentelemetry-php#10 0x000056122b3cb913 in zend_execute ()
open-telemetry/opentelemetry-php#11 0x00007f1bc7c947dc in bf_load_embedded_code () from /usr/local/lib/php/extensions/no-debug-non-zts-20220829/blackfire.so
open-telemetry/opentelemetry-php#12 0x00007f1bc7c7b86d in zm_activate_blackfire () from /usr/local/lib/php/extensions/no-debug-non-zts-20220829/blackfire.so
open-telemetry/opentelemetry-php#13 0x000056122b362020 in zend_activate_modules ()
open-telemetry/opentelemetry-php#14 0x000056122b2f5e30 in php_request_startup ()
open-telemetry/opentelemetry-php#15 0x000056122b43ec70 in ?? ()
open-telemetry/opentelemetry-php#16 0x000056122b046061 in ?? ()
open-telemetry/opentelemetry-php#17 0x00007f1bc87749ca in ?? () from /lib/ld-musl-x86_64.so.1
open-telemetry/opentelemetry-php#18 0x00007f1bc87749a2 in ?? () from /lib/ld-musl-x86_64.so.1
open-telemetry/opentelemetry-php#19 0x00007ffd5f83ef10 in ?? ()
open-telemetry/opentelemetry-php#20 0x0000000000000000 in ?? ()

brettmc avatar Jun 14 '23 11:06 brettmc

Not fixed, but avoided, by open-telemetry/opentelemetry-php-instrumentation#83 Until we do have a proper fix, we decided at SIG to disable the extension in case of conflict.

brettmc avatar Aug 21 '23 23:08 brettmc

Using main, I was able to have both blackfire and opentelemetry running without segfault. I think we can say that this is fixed by open-telemetry/opentelemetry-php-instrumentation#102 and I will remove the conflict configuration to enable blackfire to run alongside opentelemetry.

brettmc avatar Oct 18 '23 23:10 brettmc