apm-agent-php
apm-agent-php copied to clipboard
apm-agent-php and xdebug extensions enabled together cause a memory leak in php7.4-fpm
Describe the bug
Using nginx + php7.4-fpm with extensions apm-agent-php and xdebug enabled together cause memory leak. Disabling either stops the leak.
To Reproduce
I have reproduced this issue in a docker container.
Dockerfile
FROM ubuntu:20.04
RUN apt update && \
DEBIAN_FRONTEND=noninteractive apt install -y \
php \
php-fpm \
nginx \
curl \
wget \
openssl \
ca-certificates \
php-xdebug
RUN apt purge -y apache2
RUN echo \
'server { \
listen 80 default_server; \
server_name localhost; \
location ~ ^/status$ { \
allow 127.0.0.1;\
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\
fastcgi_index index.php;\
include fastcgi_params;\
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;\
}\
}' > /etc/nginx/sites-available/default
RUN sed -i 's#;pm.status_path = /status#pm.status_path = /status#g' /etc/php/7.4/fpm/pool.d/www.conf
# These here are the two critical lines. xdebug is enabled by default if it's installed
# Uncomment the next line to stop the leak
# RUN phpdismod xdebug
#OR comment this line to stop the leak
RUN wget https://github.com/elastic/apm-agent-php/releases/download/v1.3/apm-agent-php_1.3_all.deb && dpkg -i apm-agent-php_1.3_all.deb
CMD php-fpm7.4 && nginx && nginx -s reload && watch -n1 curl http://localhost/status?full
Then, to build and run it:
docker build . -t leak
docker run -it leak
Observe the php-fpm memory using htop
or similar on the host and watch memory increase without being released.
Command for convenience
top -E m -c -p $(pgrep -d',' -f 'php-fpm:')
Expected behavior No memory leak when both are enabled.
Hi, any feedback on this? We're experiencing the same issue.
And we also faced this problem but on php7.2.
This pool handled only/status requests
127.0.0.1 - 14/Dec/2022:13:30:57 +0300 "GET /status" 200
127.0.0.1 - 14/Dec/2022:13:30:57 +0300 "GET /status" 200
127.0.0.1 - 14/Dec/2022:13:31:07 +0300 "GET /status" 200
127.0.0.1 - 14/Dec/2022:13:31:07 +0300 "GET /status" 200
Application versions:
- Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.33-1+ubuntu20.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies with Xdebug v2.9.6, Copyright (c) 2002-2020, by Derick Rethans
- Elastic APM PHP installed from https://github.com/elastic/apm-agent-php/releases/download/v1.6.1/apm-agent-php_1.6.1_all.deb
Xdebug and APM agent with default settings.
@thomas-thorburn-connect , @abra7134 @waynegemmell Did you have a chance to try the latest agent release (v1.10.0) - does it still result in memory leak?
@SergeyKleyman On ubuntu 20.04 with php7.4-fpm apm agent v1.10.0 still leaks, on ubuntu 22.04 with php7.4-fpm there is no leak on ubuntu 22.04 with php8.1-fpm there is no leak
updated dockerfiles to reproduce leak on 20.04 and show no leak on 22.04
ubuntu 20.04 php 7.4
FROM ubuntu:20.04
RUN apt update && \
DEBIAN_FRONTEND=noninteractive apt install -y \
php \
php-fpm \
nginx \
curl \
wget \
openssl \
ca-certificates \
php-xdebug
RUN apt purge -y apache2
RUN echo \
'server { \
listen 80 default_server; \
server_name localhost; \
location ~ ^/status$ { \
allow 127.0.0.1;\
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\
fastcgi_index index.php;\
include fastcgi_params;\
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;\
}\
}' > /etc/nginx/sites-available/default
RUN sed -i 's#;pm.status_path = /status#pm.status_path = /status#g' /etc/php/7.4/fpm/pool.d/www.conf
# These here are the two critical lines. xdebug is enabled by default if it's installed
# Uncomment the next line to stop the leak
# RUN phpdismod xdebug
#OR comment this line to stop the leak
RUN wget https://github.com/elastic/apm-agent-php/releases/download/v1.10.0/apm-agent-php_1.10.0_all.deb && dpkg -i apm-agent-php_1.10.0_all.deb
CMD php-fpm7.4 && nginx && nginx -s reload && watch -n1 curl http://localhost/status?full
ubuntu 22.04 php 8.1
FROM ubuntu:22.04
RUN apt update && \
DEBIAN_FRONTEND=noninteractive apt install -y \
php \
php-fpm \
nginx \
curl \
wget \
openssl \
ca-certificates \
php-xdebug
RUN apt purge -y apache2
RUN echo \
'server { \
listen 80 default_server; \
server_name localhost; \
location ~ ^/status$ { \
allow 127.0.0.1;\
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\
fastcgi_index index.php;\
include fastcgi_params;\
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;\
}\
}' > /etc/nginx/sites-available/default
RUN sed -i 's#;pm.status_path = /status#pm.status_path = /status#g' /etc/php/8.1/fpm/pool.d/www.conf
# These here are the two critical lines. xdebug is enabled by default if it's installed
# Uncomment the next line to stop the leak
# RUN phpdismod xdebug
#OR comment this line to stop the leak
RUN wget https://github.com/elastic/apm-agent-php/releases/download/v1.10.0/apm-agent-php_1.10.0_all.deb && dpkg -i apm-agent-php_1.10.0_all.deb
CMD php-fpm8.1 && nginx && nginx -s reload && watch -n1 curl http://localhost/status?full
ubuntu 22.04 php 7.4
FROM ubuntu:22.04
RUN apt update && apt install -y software-properties-common
RUN add-apt-repository ppa:ondrej/php -y
RUN apt update && \
DEBIAN_FRONTEND=noninteractive apt install -y \
php7.4 \
php7.4-fpm \
nginx \
curl \
wget \
openssl \
ca-certificates \
php7.4-xdebug
RUN apt purge -y apache2
RUN update-alternatives --set php /usr/bin/php7.4
RUN echo \
'server { \
listen 80 default_server; \
server_name localhost; \
location ~ ^/status$ { \
allow 127.0.0.1;\
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\
fastcgi_index index.php;\
include fastcgi_params;\
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;\
}\
}' > /etc/nginx/sites-available/default
RUN sed -i 's#;pm.status_path = /status#pm.status_path = /status#g' /etc/php/7.4/fpm/pool.d/www.conf
# These here are the two critical lines. xdebug is enabled by default if it's installed
# Uncomment the next line to stop the leak
# RUN phpdismod xdebug
RUN phpenmod xdebug
#OR comment this line to stop the leak
RUN wget https://github.com/elastic/apm-agent-php/releases/download/v1.10.0/apm-agent-php_1.10.0_all.deb && dpkg -i apm-agent-php_1.10.0_all.deb
RUN mkdir -p /run/php
CMD php-fpm7.4 && sleep 5 && nginx && nginx -s reload && watch -n0.1 curl http://localhost/status?full