0

My VSCode in WSL:Ubuntu is unable to listen to the xdebug port, because it is blocked by some docker-proxy.

I was following this Solution, but trying VSCode to listen to the xdebug port, results in the following error:

Error: listen EADDRINUSE: address already in use :::9003

Can anyone help with connecting VSCode to xdebug?

Windows 11 says the port is already allocated by wslhost:

PS C:\WINDOWS\system32> Get-Process -Id (Get-NetTCPConnection -LocalPort 9003).OwningProcess

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    285      47     2288       4748       0,05  19480   1 wslhost

Ubuntu tells, its allocated by some docker-proxy:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:9003            0.0.0.0:*               LISTEN      17210/docker-proxy
tcp6       0      0 :::9003                 :::*                    LISTEN      17217/docker-proxy

docker-compose-version: docker-compose version 1.25.0

The xdebug.log says:

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

For sure as long as nothing is listening.

As to xdebug.client_host I'v tried:

Removing the Expose directive from Dockerfile/docker-compose as in this comment doesn't remove the error neither.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
SeliusX
  • 51
  • 6
  • 1
    `xdebug://gateway` and `xdebug://nameserver` are not in a released version yet, so they wouldn't work :-) – Derick May 20 '22 at 10:44
  • 1) Restart PC, may help 2) Double check that none of the active/running Docker images have such 9003 port used or exposed by any service. 3) Shutdown images one by another while you have ZERO Docker images running -- is it still there? 4) Shutdown Docker -- is it still there? 4) Use another Xdebug port (e.g. 9004 or some another number) -- in both php.ini and VSCode ofc. – LazyOne May 20 '22 at 12:35
  • Thanks you for you help. I removed every expose of 9003 and the php-fpm-container is the only container with port-binding `9003:9003`. If I remove it from docker-compose.yml the port is free for listening. But VSCode still did'nt catch the debug session even if I configure **xdebug.client_host** with the ip from ubuntu's **/etc/resolv.conf**. – SeliusX May 20 '22 at 15:02

1 Answers1

2

Solved it. For others with this challenge:

Inside of wsl-ubuntu -> docker-containter host.docker.internal directs to the wrong ip. In the wsl-distribution the file /etc/resolv.conf is the ip of the windows host. To get the correct ip use this answer: How to get the primary IP address of the local machine on Linux and OS X?

My solution is to define an env-variable with this ip:

alias docker_compose_local_ip="ifconfig eth0 | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'"
export DOCKER_COMPOSE_LOCAL_IP=$(docker_compose_local_ip)

and configure the container with it:

services:
  service-name:
    environment:
      - XDEBUG_CONFIG=client_host=${DOCKER_COMPOSE_LOCAL_IP} ...
SeliusX
  • 51
  • 6