1

Environment

I'm using

  • Windows 10
  • Docker Desktop 3 for Windows
    • With a container with the environment variable PHP_IDE_CONFIG=serverName=Docker
  • XDebug 3
  • PhpStorm 2021.1.2
    • With an entry in Settings > PHP > Servers called "Docker"

With these XDebug settings:

php -i | grep xdebug
xdebug.cli_color => 0
xdebug.client_discovery_header => no value
xdebug.client_host => host.docker.internal
xdebug.client_port => 9003
xdebug.cloud_id => no value
xdebug.collect_assignments => Off
xdebug.collect_return => Off
xdebug.connect_timeout_ms => 200
xdebug.discover_client_host => Off
xdebug.dump.COOKIE => no value
xdebug.dump.ENV => no value
xdebug.dump.FILES => no value
xdebug.dump.GET => no value
xdebug.dump.POST => no value
xdebug.dump.REQUEST => no value
xdebug.dump.SERVER => no value
xdebug.dump.SESSION => no value
xdebug.dump_globals => On
xdebug.dump_once => On
xdebug.dump_undefined => Off
xdebug.file_link_format => no value
xdebug.filename_format => no value
xdebug.force_display_errors => Off
xdebug.force_error_reporting => 0
xdebug.gc_stats_output_name => gcstats.%p
xdebug.halt_level => 0 
xdebug.idekey => no value
xdebug.log => /var/log/foo/xdebug.log
xdebug.log_level => 7
xdebug.max_nesting_level => 256
xdebug.max_stack_frames => -1
xdebug.mode => develop,coverage,debug,gcstats,profile,trace
xdebug.output_dir => /var/log/foo
xdebug.profiler_append => Off
xdebug.profiler_output_name => cachegrind.out.%p
xdebug.scream => Off
xdebug.show_error_trace => Off
xdebug.show_exception_trace => Off
xdebug.show_local_vars => Off
xdebug.start_upon_error => default
xdebug.start_with_request => yes
xdebug.trace_format => 0
xdebug.trace_options => 0
xdebug.trace_output_name => trace.%c
xdebug.trigger_value => no value
xdebug.var_display_max_children => 128
xdebug.var_display_max_data => 512
xdebug.var_display_max_depth => 3

There are also background processes happening automatically which might possibly be getting processed by XDebug in a way that creates more connections to PhpStorm than its "Max. simultaneous connections" value, but the problem seems to happen even if it's set to its highest value (20) without ever appearing to create more than a couple tabs in the debug panel.

Problem

XDebug works for both browser requests and CLI scripts, and I can successfully initiate step debugging, but after a few minutes, the connection between XDebug and PhpStorm always seems to disappear along with a "broken pipe" warning when XDebug tries to send a "stopping" response, and subsequent requests/scripts hang indefinitely. The XDebug logs show this:

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

[95] [Step Debug] WARN: 2021-05-26 20:55:26.677006: There was a problem sending 179 bytes on socket 5: Broken pipe.
[95] Log closed at 2021-05-26 20:55:26.677314

Troubleshooting

When execution is hanging without PhpStorm's debug panel showing any activity

  • Turning off "Listening for PHP Debug Connections" in the IDE results in scripts immediately resuming execution, but turning it back on results in the next request also hanging indefinitely
  • Restarting PhpStorm not only allows the request/script's execution to resume, but it also allows step debugging to resume. But after a few minutes, step debugging is once again unavailable and requests hang indefinitely.

Investigation

  • This comment suggests that this is because the IDE is closing the connection before XDebug can send the "stopping" response.
  • It appears that there is a currently unresolved bug in Windows Docker Desktop that makes Docker drop idle TCP connections after a period of inactivity, causing XDebug sessions to end, even if a script is continuing to run.

Questions

  • Is PhpStorm responsible for closing the connection, and can it be configured not to?
  • Is Docker responsible closing the connection, and is there a workaround?
  • Could it be something else entirely?
Phantom Watson
  • 2,667
  • 4
  • 25
  • 39
  • Check the very last comment in this thread: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000056364/comments/360001379639 -- it's for Mac but it may gave you ideas/links for your Windows OS. – LazyOne May 26 '21 at 22:19
  • @LazyOne Thanks, but this discussion suggests that there isn't yet a way to do that same thing in Windows: https://github.com/docker/for-mac/issues/2197 – Phantom Watson May 26 '21 at 22:40
  • Yeah, should have checked that (what ticket it references) before -- you already have mentioned the same Windows ticket. Sorry for that. Sadly no better ideas from me. – LazyOne May 26 '21 at 22:50
  • 1
    Anyway: can you make SSH connection (from your Windows machine into the docker container)? If you can -- perhaps debugging using SSH tunnel will do better here... (it will be an incoming connection and it may be handled differently) – LazyOne May 26 '21 at 22:52
  • It happens when the remote (i.e. PhpStorm) has closed the connection. I can't see the command that PhpStorm sent (you just didn't have enough of your log in the question). Xdebug doesn't decide on its own to send "stopping", it would only to that in response to a command - usually. – Derick May 27 '21 at 08:14
  • 2
    It would be great if you could also contact us (PhpStorm support team) directly via Help | Contact Support. We need to check both IDE & XDebug logs to see if there's anything wrong on our end. So far I can't see any similar reports on our tracker. – Dmitrii May 27 '21 at 13:11

0 Answers0