Environment
I'm using
- Windows 10
- Docker Desktop 3 for Windows
- With a container with the environment variable
PHP_IDE_CONFIG=serverName=Docker
- With a container with the environment variable
- 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?