View Issue Details

IDProjectCategoryView StatusLast Update
0002258XdebugStep Debuggingpublic2024-10-09 10:04
Reportermarcus90 Assigned Toderick  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionnot fixable 
Product Version3.2.2 
Summary0002258: Cannot enable step debugging with remote Docker container
Description

Hello,

I cannot make step debugging working in a remote Docker container.
If I check the xdebug logs I see: The debugging client closed the connection on socket 8: Broken pipe (error: 32).

I tried with Xdebug 3.0, 3.1, 3.2 and 3.3 with no success.

Steps To Reproduce

OS: Ubuntu 22.04.4 LTS
Docker: Docker version 25.0.3, build 4debf41

docker-compose.yml:

version: '3.5'

services:
  nginx:
    image: 'nginx:1.21-alpine'
    container_name: '${DOCKER_STACK}_nginx'
    restart: always
    working_dir: /var/www
    volumes:
      - './../:/var/www'
      - './docker/nginx.conf:/etc/nginx/conf.d/default.conf'
    networks:
      - default
      - web
  fpm:
    build:
      context: ./docker
      dockerfile: fpm-bullseye.dockerfile
    container_name: '${DOCKER_STACK}_fpm'
    extra_hosts:
      - "host.docker.internal:host-gateway"
    ports:
      - "9003:9003"
    restart: always
    working_dir: /var/www
    env_file: .env
    volumes:
      - './../:/var/www'
      - './docker/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini'
      - './docker/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini'
    networks:
      - default

xdebug.ini:

zend_extension=xdebug

[xdebug]
xdebug.mode=develop,debug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.log=/tmp/xdebug.log
xdebug.log_level=10

error_reporting.ini:

error_reporting=E_ALL

nginx.conf:

server {
    listen      80;
    listen      [::]:80;
    root        /var/www/public;
    index       index.php index.html;

    gzip on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    gzip_types application/json application/xml application/x-javascript application/javascript text/javascript text/css;
    gzip_vary on;

    add_header X-Content-Type-Options "nosniff";
    add_header X-Frame-Options "SAMEORIGIN";

    client_max_body_size 4m;

    location = /favicon.ico {
        return 204;
        access_log off;
        log_not_found off;
    }

    location ~* \.(js|css|png|jpe?g|gif|ico|svg|woff|woff2)$ {
        expires 30d;
        access_log off;
        log_not_found off;
    }

    location / {

        try_files $uri $uri/ /index.php?$args;

        location ~ \.php$ {
            include        fastcgi_params;
            fastcgi_pass   fpm:9000;
            fastcgi_index  index.php;
            fastcgi_param  PHP_VALUE  "expose_php=0
                memory_limit=128M
                post_max_size=16M
                upload_max_filesize=16M
                max_execution_time=60
                max_input_time=60
                log_errors=On
                error_log=/dev/stderr";
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param SERVER_NAME $host;
        }
    }
}

Dockerfile:

FROM php:8.0.29-fpm-bullseye

RUN apt-get update -y && \
    apt-get -y install --no-install-recommends whiptail libtidy-dev apt-utils libicu-dev git gcc make autoconf libc-dev pkg-config libzip-dev
#    # Xdebug
RUN pecl install xdebug-3.2.2 && docker-php-ext-enable xdebug
    # Cleanup
RUN apt-get remove -y git && \
    apt-get autoremove -y && \
    apt-get clean && \
    rm -rf /etc/cron.*/* && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
    # Cron hack
RUN touch /tmp/run_scheduler
Additional Information

/tmp/xdebug.log (after accessing an endpoint via Postman or browser):

[7] Log opened at 2024-03-31 10:54:28.922484
[7] [Step Debug] INFO: Connecting to configured address/port: host.docker.internal:9003.
[7] [Step Debug] INFO: Connected to debugging client: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port).
[7] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/public/index.php" language="PHP" xdebug:language_version="8.0.30" protocol_version="1.0" appid="7"><engine version="3.2.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2023 by Derick Rethans]]></copyright></init>

[7] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

[7] [Step Debug] WARN: The debugging client closed the connection on socket 8: Broken pipe (error: 32).
[7] Log closed at 2024-03-31 10:54:28.968976

Doing telnet 127.0.0.1 9003 gives the following output:

Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Connection closed by foreign host.

I can telnet successfully on port 9003 if assigned to an nginx container for example so there is no firewall issue.

TagsNo tags attached.
Attached Files
xdebug.png (513,537 bytes)
Operating SystemUbuntu 22.04.4 LTS
PHP Version8.0.20-8.0.29

Activities

derick

2024-04-15 12:40

administrator   ~0006900

The debugger connected correctly to your IDE, and after that, Xdebug sent the <init packet.
Your image also shows that a connection was made.
It is really the IDE that closed the connection here, so you will need to check in the logs on that side, what is going on. You didn't say which one it is, so can't point you further towards having a look there.

derick

2024-05-06 10:25

administrator   ~0006938

Can you provide the requested feedback please?

marcus90

2024-05-09 18:24

reporter   ~0006950

The IDE is PhpStorm v2021.2.2. I attached a screenshot with the config.

Can you provide the requested feedback please?
I don't think I know how to do this. Can you help me ?

Thank you!

phpstorm_xdebug_config.png (93,801 bytes)   
phpstorm_xdebug_config.png (93,801 bytes)   

derick

2024-05-10 15:16

administrator   ~0006951

You're going to have to take this up with JetBrains' support for PhpStorm them. I don't know how to make it create logs as to where it terminated the connection.

marcus90

2024-05-11 07:26

reporter   ~0006956

Thank you for your feedback. I will open a ticket with them.

derick

2024-06-05 09:59

administrator   ~0006966

If you have their ticket number, feel free to add it here. I would want to close this ticket as "Can't Fix" as it's unlikely to be a bug here.

marcus90

2024-10-08 15:04

reporter   ~0007057

Hello,
I finally found the issue. The problem is that my ISP is using CGNAT, so PhpStorm and Xdebug are actually OK.
Sorry for the inconvenience.

derick

2024-10-08 15:12

administrator   ~0007058

Hi!

I had never heard of CGNAT until now. But I don't quite understand how this is important, as the whole idea by Docker is that you run everything on your local machine? How would your ISP get in between?

cheers,
Derick

vic

2024-10-08 19:01

reporter   ~0007069

Actually I'm getting same error using docker. IDE is PHPStorm.
my docker-compose content:

version: '3'

services:
  php:
    container_name: testing-php
    image: php:8.2.9-fpm
    depends_on:
      - db
    environment:
      WEB_DOCUMENT_ROOT: /app/public
      PHP_IDE_CONFIG: 'serverName=Xdebug'
      XDEBUG_MODE: debug
      XDEBUG_CONFIG: client_host=host.docker.internal client_port=9003 idekey=PHPSTORM
      XDEBUG_START_WITH_REQUEST: "yes"
    working_dir: /app
    volumes:
      - ./app:/app
      - ./:/project/
    ports:
      - '80:80'
      - '9003:9003'
      - '9000:9000'
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    command: >
      sh -c "pecl install xdebug && 
             docker-php-ext-enable xdebug &&
             echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini &&
             echo 'xdebug.mode=debug' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini &&
             echo 'xdebug.start_with_request=yes' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini &&
             echo 'xdebug.log=/tmp/xdebug.log' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini &&
             php -S 0.0.0.0:80 -t /app/public"

marcus90

2024-10-09 10:04

reporter   ~0007071

@Derick

The Docker dev instance is in the cloud. This is why I believe CGNAT might actually be the issue. Cannot say 100% sure, but very close to :)
I tried tens of configs so that's why I think at least 1 of them should have worked in normal conditions.

Issue History

Date Modified Username Field Change
2024-03-31 11:07 marcus90 New Issue
2024-03-31 11:07 marcus90 File Added: xdebug.png
2024-04-15 12:40 derick Assigned To => derick
2024-04-15 12:40 derick Status new => feedback
2024-04-15 12:40 derick Note Added: 0006900
2024-05-06 10:25 derick Note Added: 0006938
2024-05-09 18:24 marcus90 Note Added: 0006950
2024-05-09 18:24 marcus90 File Added: phpstorm_xdebug_config.png
2024-05-09 18:24 marcus90 Status feedback => assigned
2024-05-10 15:16 derick Status assigned => feedback
2024-05-10 15:16 derick Note Added: 0006951
2024-05-11 07:26 marcus90 Note Added: 0006956
2024-05-11 07:26 marcus90 Status feedback => assigned
2024-06-05 09:59 derick Status assigned => feedback
2024-06-05 09:59 derick Note Added: 0006966
2024-07-17 18:14 derick Status feedback => resolved
2024-07-17 18:14 derick Resolution open => not fixable
2024-10-08 15:04 marcus90 Note Added: 0007057
2024-10-08 15:12 derick Note Added: 0007058
2024-10-08 19:01 vic Note Added: 0007069
2024-10-09 10:04 marcus90 Note Added: 0007071