vscode-php-debug icon indicating copy to clipboard operation
vscode-php-debug copied to clipboard

Container time-out connecting to debugging client (Xdebug)

Open goncalovf opened this issue 2 years ago • 5 comments

Type: Bug

I'm running a project from WSL2 in a Windows machine. Yesterday, my VS Code auto-updated and, since then, the wp Docker container (see below) cannot connect with XDebug. I always get the following error:

Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port).

Below I detail my project.

I have the following docker-compose.yml:

version: "3.9"

services:

  # Shared #

  nginx-proxy:
    image: jwilder/nginx-proxy:0.9.0
    depends_on:
      - wordpress
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - certs:/etc/nginx/certs
      - vhost.d:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - /var/run/docker.sock:/tmp/docker.sock:ro

  db:
    image: mysql:5.7
    ports:
      - "3306:3306"
    volumes:
      - db_data:/var/lib/mysql
      - ./docker/db/conf.d:/etc/mysql/conf.d
      - ./docker/db/init-db.sql:/docker-entrypoint-initdb.d/init-db.sql
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

  build: ./docker/mkcert
  volumes:
    - certs:/root/.local/share/mkcert
  command: >
    sh -c "mkcert -cert-file '${DEV_URL:-ff.local}.crt' -key-file '${DEV_URL:-ff.local}.key' '${DEV_URL:-ff.local}' '*.${DEV_URL:-ff.local}'"

  wordpress_ff:
    build: ./docker/wp
    ports:
      - "9090:80"
    depends_on:
      - db
    user: www-data
    volumes:
      - ./docker/wp/volume.d:/var/www/html/volume.d/
      - ./mu-plugins:/var/www/html/wp-content/mu-plugins
      - ./plugins:/var/www/html/wp-content/plugins
      - ./themes:/var/www/html/wp-content/themes
      - ./uploads:/var/www/html/wp-content/uploads
      - ./debug.log:/var/www/html/wp-content/debug.log
      - ./docker/wp/object-cache.php:/var/www/html/wp-content/object-cache.php
      # For phpunit:
      - ../wordpress-develop:/tmp/wordpress-tests-lib
      - ./plugins:/tmp/wordpress-tests-lib/src/wp-content/plugins
      - ./docker/wp/wp-tests-config.php:/tmp/wordpress-tests-lib/wp-tests-config.php
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: ff
      WORDPRESS_TABLE_PREFIX: wp_
      WORDPRESS_DEBUG: 'true'
      SMTPSERVER: mailhog
      EMAIL: local@${DEV_URL:-ff.local}
      VIRTUAL_HOST: ${DEV_URL:-ff.local}, *.${DEV_URL:-ff.local}
      VIRTUAL_PORT: 9090
      VIRTUAL_PROTO: http
      WP_DEVELOP_DIR: /tmp/wordpress-tests-lib/
    extra_hosts:
      - 'host.docker.internal:172.18.238.16'
      - 'ff.local:127.0.0.1'

volumes:
  db_data:
  certs:
  vhost.d:
  html:
  acme:

In ./docker/wp, I have the following Dockerfile:

FROM wordpress:6.4.2-php8.2-apache

COPY --from=composer /usr/bin/composer /usr/bin/composer

# Development tooling dependencies
RUN apt-get update \
	&& apt-get install -y --no-install-recommends \
		bash less default-mysql-client git zip unzip \
		curl pv \
		msmtp libz-dev libmemcached-dev \
	&& rm -rf /var/lib/apt/lists/* \
    && pecl install xdebug memcache \
    && docker-php-ext-enable xdebug memcache;

# Include our custom config for PHP and Xdebug.
COPY config/php/* /usr/local/etc/php/conf.d/

# Install Composer dependencies and add vendor/bin to the path.
COPY composer.json .
RUN composer install
ENV PATH /var/www/html/vendor/bin:$PATH

WORKDIR /var/www/html/

# Register a directory to be used as a volume.
RUN mkdir -p /volume.d
VOLUME /volume.d

In ./docker/wp/php, I have the following php.ini:

memory_limit = -1
upload_max_filesize = 1G
post_max_size = 1G

# Forward mail to the MailHog container. Use SMTPSERVER and EMAIL
# environment variables to specify --host and --from values.
sendmail_path = "/usr/bin/msmtp --port=1025 --read-recipients"

[xdebug]
# Enable remote Xdebug.
xdebug.mode = debug
xdebug.scream = 1
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9003
xdebug.client_host = host.docker.internal
xdebug.start_with_request = yes

[opcache]
opcache.enable = 1
opcache.validate_timestamps = 1

Here's my .vscode/launch.json:

{
	"version": "0.2.0",
	"configurations": [
		{
			"name": "Main Xdebug",
			"type": "php",
			"request": "launch",
			"port": 9003,
			"pathMappings": {
				"/var/www/html/wp-admin": "${workspaceFolder}/wordpress/wp-admin",
				"/var/www/html/wp-content/plugins": "${workspaceFolder}/plugins",
				"/var/www/html/wp-content/themes": "${workspaceFolder}/themes",
				"/var/www/html/wp-includes": "${workspaceFolder}/wordpress/wp-includes",
				"/var/www/html/wp-content/object-cache.php": "${workspaceFolder}/docker/wp/object-cache.php"
			}
		},
	]
}

My current VS Code version:

Version: 1.92.0 (user setup)
Commit: b1c0a14de1414fcdaa400695b4db1c0799bc3124
Date: 2024-07-31T23:26:45.634Z
Electron: 30.1.2
ElectronBuildId: 9870757
Chromium: 124.0.6367.243
Node.js: 20.14.0
V8: 12.4.254.20-electron.0
OS: Windows_NT x64 10.0.19045

Extension version: 1.35.0 VS Code version: Code 1.92.0 (b1c0a14de1414fcdaa400695b4db1c0799bc3124, 2024-07-31T23:26:45.634Z) OS version: Windows_NT x64 10.0.19045 Modes: Remote OS version: Linux x64 5.15.153.1-microsoft-standard-WSL2

System Info
Item Value
CPUs AMD Ryzen 7 5800H with Radeon Graphics (16 x 3194)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 13.86GB (0.35GB free)
Process Argv --folder-uri=vscode-remote://wsl+Ubuntu/home/goncalovf/dev/s11/formidableforms.com --remote=wsl+Ubuntu --crash-reporter-id 52b03640-b65f-4819-8aac-60ceed826c03
Screen Reader no
VM 0%
Item Value
Remote WSL: Ubuntu
OS Linux x64 5.15.153.1-microsoft-standard-WSL2
CPUs AMD Ryzen 7 5800H with Radeon Graphics (16 x 0)
Memory (System) 5.79GB (4.04GB free)
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805:30301674
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
pythongtdpath:30769146
welcomedialogc:30910334
pythonnoceb:30805159
asynctok:30898717
pythonregdiag2:30936856
pythonmypyd1:30879173
2e7ec940:31000449
pythontbext0:30879054
accentitlementst:30995554
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
jg8ic977:31013176
pythoncenvpt:31062603
a69g1124:31058053
dvdeprecation:31068756
dwnewjupyter:31046869
impr_priority:31102340
nativerepl1:31104043
refactort:31108082
ccplti:31103428
pythonrstrctxtcf:31103194
hdi1a554:31097393
wkspc-onlycs-t:31106322
wkspc-ranged-t:31107835

goncalovf avatar Aug 03 '24 18:08 goncalovf

Here's the result of running ipconfig from my Ubuntu WSL2:

image

goncalovf avatar Aug 03 '24 18:08 goncalovf

Note that I removed some details from my project which should be irrelevant, including other Docker containers/services.

goncalovf avatar Aug 03 '24 18:08 goncalovf

If I exec into the container and run ping -c 1 host.docker.internal, I get the following:

PING host.docker.internal (172.18.238.16) 56(84) bytes of data.
From 3ef7c1dda540 (172.18.0.7) icmp_seq=1 Destination Host Unreachable

--- host.docker.internal ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms`

goncalovf avatar Aug 03 '24 18:08 goncalovf

Nevermind, the VS code version had nothing to do with it. It was an issue with my machine. Sorry for the inconvenience.

goncalovf avatar Aug 03 '24 19:08 goncalovf

Glad you could resolve it!

zobo avatar Aug 03 '24 20:08 zobo