DataDog / dd-trace-php

Datadog PHP Clients
https://docs.datadoghq.com/tracing/setup/php
Other
490 stars 152 forks source link

[BUG] `php artisan` runs into segmentation fault on laravel 9 and php8.1.0, php 8.1.1 and php 8.1.2 #1734

Closed christoph-kluge closed 1 year ago

christoph-kluge commented 2 years ago

Bug description

After debugging #1732 further I decided to split this.

Laravel 9 / Artisan is not supported.

What is strange and perhaps might be an indicator: bullseye with --enable-debug works 🤷‍♂️

Docker Image: Debian Bullseye

docker image os laravel status
php:8.1.2 debian bullseye 8
php:8.1.2 debian bullseye 9 segmentation fault
php:8.1.2-debug (with --enable-debug) debian bullseye 9 ✅ (why?)

Docker Image: Alpine

docker os laravel status
php:8.1.2-alpine alpine 8
php:8.1.2-alpine alpine 9 segmentation fault
php:8.1.2-alpine-debug (with --enable-debug) alpine 9 setup-datadog.php fails with missing ddtrace-debug.so

Tracer version

0.78.0

OS info

Host-System executing docker

MacOS Monterey 12.5.1
Chip: Apple M1 Max
Darwin 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000 arm64
% docker --version
Docker version 20.10.17, build 100c701

Reproducible Dockerfiles

Alpine + Laravel 8 / 9

FROM php:8.1.2-alpine

RUN apk add libexecinfo-dev
RUN curl -LO https://github.com/DataDog/dd-trace-php/releases/latest/download/datadog-setup.php && php datadog-setup.php --php-bin=all

RUN apk add wget git unzip gdb
RUN wget https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer -O - -q | php -- --quiet

RUN ./composer.phar create-project laravel/laravel:^8 example-laravel-8
RUN ./composer.phar create-project laravel/laravel:^9 example-laravel-9

Debian Bullseye + Laravel 8 / 9

FROM php:8.1.2

RUN apt update
RUN curl -LO https://github.com/DataDog/dd-trace-php/releases/latest/download/datadog-setup.php && php datadog-setup.php --php-bin=all

RUN apt install -y wget git unzip gdb
RUN wget https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer -O - -q | php -- --quiet

RUN ./composer.phar create-project laravel/laravel:^8 example-laravel-8
RUN ./composer.phar create-project laravel/laravel:^9 example-laravel-9

Debian Bullseye + Laravel 8 / 9 + --enable-debug - works?!

FROM christophkluge/php:8.1.2-debug

RUN apt update
RUN curl -LO https://github.com/DataDog/dd-trace-php/releases/latest/download/datadog-setup.php && php datadog-setup.php --php-bin=all

RUN apt install -y wget git unzip gdb
RUN wget https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer -O - -q | php -- --quiet

# RUN ./composer.phar create-project laravel/laravel:^8 example-laravel-8
# RUN ./composer.phar create-project laravel/laravel:^9 example-laravel-9
bwoebi commented 2 years ago

Hey @christoph-kluge,

we have recently fixed a segmentation fault (#1727) which possibly is related. Could you please verify whether the crash persists with 0.79.0?

Thanks!

morrisonlevi commented 2 years ago

@bwoebi, I can reproduce a sigsegv during building the Dockerfile:

FROM php:8.1.2

RUN apt update
RUN curl -LO https://github.com/DataDog/dd-trace-php/releases/download/0.79.0/datadog-setup.php && php datadog-setup.php --php-bin=all

RUN apt install -y wget git unzip gdb
RUN wget https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer -O - -q | php -- --quiet

RUN ./composer.phar create-project laravel/laravel:^9 example-laravel-9

Here are the last few lines:

#9 32.97 Generating optimized autoload files
#9 34.77 > Illuminate\Foundation\ComposerScripts::postAutoloadDump
#9 34.78 > @php artisan package:discover --ansi
#9 34.91 Segmentation fault
#9 34.91 Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 139

I'm on an Intel Mac in case that ends up mattering somehow.

Here's the backtrace:

Core was generated by `/usr/local/bin/php -d allow_url_fopen=1 -d disable_functions= -d memory_limit=1'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00005644c9bbc91b in zend_observer_fcall_end ()
(gdb) bt
#0  0x00005644c9bbc91b in zend_observer_fcall_end ()
#1  0x00005644c9b8c2e7 in execute_ex ()
#2  0x00005644c9b1a2a7 in zend_call_function ()
#3  0x00005644c9b1a6c5 in zend_call_known_function ()
#4  0x00005644c99ea6ce in ?? ()
#5  0x00007f6d3c7a2ff8 in zai_interceptor_execute_internal_impl (execute_data=0x7f6d3ca14090, 
    return_value=0x7f6d3ca13fd0, prev=<optimized out>)
    at /home/circleci/datadog/tmp/build_extension/zend_abstract_interface/interceptor/php8/interceptor.c:664
#6  0x00005644c9839aa4 in ?? ()
#7  0x00005644c983a256 in ?? ()
#8  0x00005644c9b94f5f in zend_execute ()
#9  0x00005644c9b2880d in zend_execute_scripts ()
#10 0x00005644c9ac4db1 in php_execute_script ()
#11 0x00005644c9c08a41 in ?? ()
#12 0x00005644c98449b1 in ?? ()
#13 0x00007f6d3f65cd0a in __libc_start_main (main=0x5644c98445e0, argc=10, argv=0x7fff467519d8, init=<optimized out>, 
    fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fff467519c8) at ../csu/libc-start.c:308
#14 0x00005644c984514a in _start ()
morrisonlevi commented 2 years ago

A possibly important finding: I did not crash on php:8.1.10. Of course, sometimes things just subtly change and it hides the issue, rather than something being fixed.

I also didn't crash on PHP 8.1.3, 8.1.4, nor 8.1.6 (I did a sort of bisect). Again, could be something subtle, but in any case it's always reproduced with the exact Dockerfile I showed above.

bwoebi commented 2 years ago

PHP 8.1.3 had a critical bugfix related to observing attributes. (https://github.com/php/php-src/commit/2f6a06ccb0ef78e6122bb9e67f9b8b1ad07776e1)

That's the only thing which stands out to me, and it's not really fixable, except by using a version newer than 8.1.2 I guess.

christoph-kluge commented 2 years ago

Changing the php image to 8.1.3 fixed this issue.

Perhaps it's worth adding some version check inside datadog-setup.php and prevent installs if you run php 8.1 below 8.1.3.

bwoebi commented 2 years ago

The problem is that most code on PHP 8.1.0-8.1.2 is fine, unless it's very new code (using attributes). Adding a check might break other clients setup, where it currently runs fine. There are no great solutions to that, I think.

christoph-kluge commented 2 years ago

True. I totally forgot this fact. It only applys to laravel 9 + ddtrace and php 8.1.0 - 8.1.2.

My idea was how to prevent this for some other people. Anyway I've changed the title to me a bit more precise if some else searches for it.

In my personal opinion this issue can be closed.

krakjoe commented 1 year ago

Since @christoph-kluge is happy to close, and since we can't really think of any good solution (except using a version that includes the fix upstream), I'm closing this now.

It remains for reference, thanks for the report 👍