uselagoon / lagoon

Lagoon, the developer-focused application delivery platform
https://docs.lagoon.sh/
Apache License 2.0
568 stars 148 forks source link

Xdebug stops working on linux every once in a while #988

Closed blazeyo closed 3 years ago

blazeyo commented 5 years ago

Describe the bug Xdebug stops working on linux every once in a while.

To Reproduce This is what happens on linux (Ubuntu, Docker version 18.09.3)

ping docker.for.mac.localhost
PING docker.for.mac.localhost (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.108 ms
64 bytes from 127.0.0.1: seq=1 ttl=64 time=0.168 ms

Because of that the xdebug entrypoint sets the xdebug.remote_host setting to 127.0.0.1 and this breaks xdebug.

Expected behavior xdebug.remote_host is set to point to the host machine.

My workaround Replacing the entrypoint's get_dockerhost function with the following snippet fixes it for me. I don't know if that's the correct solution for all the supported platforms.

get_dockerhost() {
  # https://github.com/amazeeio/pygmy/blob/267ba143158548628f190f05ecb5cb2c19212038/lib/pygmy/resolv_osx.rb#L26
  if busybox timeout -t 1 ping -c1 172.16.172.16 &> /dev/null; then
    echo "172.16.172.16"
    return
  fi

   # Fallback to default gateway (should work on Linux) see https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach
  echo $(route -n | awk '/UG[ \t]/{print $2}')
  return
}
tobybellwood commented 3 years ago

This was fixed in https://github.com/uselagoon/lagoon-images/blob/main/images/php-fpm/entrypoints/60-php-xdebug.sh