elastic / elastic/apm-agent-php

apm-agent-php and xdebug extensions enabled together cause a memory leak in php7.4-fpm

Open
#548 4 comments 0 reactions 0 assignees View on GitHub
agent-php bug priority: medium triaged
Dominant language
PHP
Stars
268
Forks
86
PR merge metrics
No merged PRs in 30d

Description

**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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.