View Issue Details

IDProjectCategoryView StatusLast Update
0001771XdebugStep Debuggingpublic2020-03-25 15:59
Reportersamuel.nogueiraAssigned Toderick 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
PlatformOSLinuxOS Version
Product Version2.9.4 
Target VersionFixed in Version 
Summary0001771: Cannot step debug fork child processes
DescriptionWhile debugging a script which forks, I expected step-debugging to be available in child processes, but only works in the parent process instead (xdebug log in attachment).
Steps To ReproduceDebug the following script, with 2 breakpoints:

<code php>
<?php

echo "started\n";
if ($child = pcntl_fork()) {
    sleep(5);
    echo "hello from parent\n"; //breakpoint no. 1 here
    pcntl_waitpid($child, $status);
    echo "finished\n";
} else {
    echo "hello from child\n"; //breakpoint no. 2 here
}
</code>

Expected execution to immediately stop at breakpoint no. 2
Execution stops after 5 seconds at breakpoint no. 1 instead
Additional InformationPHP 7.4.0 (cli) (built: Nov 28 2019 20:31:53) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Xdebug v2.9.4, Copyright (c) 2002-2020, by Derick Rethans


PhpStorm 2019.3.4
Build #PS-193.6911.26, built on March 18, 2020

Docker version 19.03.3, build a872fc2f86
TagsNo tags attached.
Operating SystemLinux
PHP Version7.4.0-7.4.4

Activities

samuel.nogueira

2020-03-24 18:55

reporter  

Dockerfile (116 bytes)
FROM php

RUN docker-php-ext-install pcntl \
    && pecl install xdebug-2.9.4 \
    && docker-php-ext-enable xdebug
Dockerfile (116 bytes)
script.php (249 bytes)
xdebug.log (14,322 bytes)

samuel.nogueira

2020-03-24 18:58

reporter   ~0005346

Seems this wasn't an issue in versions prior to 2.7.0, could be related to https://bugs.xdebug.org/view.php?id=938

derick

2020-03-25 11:09

administrator   ~0005347

Hi,

Prior to 2.7.0 this didn't work at all :-)

I think the problem here is that Xdebug only checks whether to make a debug connection when a function is called, otherwise it would be way too slow. (It's already too slow, but there is 0001755, with a PR: https://github.com/xdebug/xdebug/pull/556). I think that if you put the "echo" in a function, and call that function in your "} else {" case, you will see that the forked process will make a separate connection to your IDE.

cheers,
Derick

samuel.nogueira

2020-03-25 11:58

reporter  

Screencast from 25-03-2020 11:44:08.webm (346,800 bytes)

samuel.nogueira

2020-03-25 11:58

reporter   ~0005348

Couldn't test with newer PHP versions, but at least with PHP 7.2.29 + Xdebug 2.6.1, it was working, execution stopped in each breakpoint, even without changes to the script (still using echo). Kindly see attached Xdebug remote log, Dockerfile and screen cast:

xdebug261.log (23,585 bytes)
xdebug261.Dockerfile (120 bytes)

derick

2020-03-25 12:06

administrator   ~0005349

Did you not see/read my second paragraph?

I think the problem here is that Xdebug only checks whether to make a debug connection when a function is called, otherwise it would be way too slow. (It's already too slow, but there is 0001755, with a PR: https://github.com/xdebug/xdebug/pull/556). I think that if you put the "echo" in a function, and call that function in your "} else {" case, you will see that the forked process will make a separate connection to your IDE.

samuel.nogueira

2020-03-25 15:13

reporter   ~0005350

I did, and I did try it out first, but it didn't made a difference, sorry I didn't mention that in the note.
Attached updated script with function calls instead of echo + screen cast + xdebug log.
Please let me know if there's anything I can do to help you replicate the issue.

xdebug-2.log (14,325 bytes)
script-2.php (342 bytes)
Screencast from 25-03-2020 15:10:32.webm (305,730 bytes)

derick

2020-03-25 15:25

administrator   ~0005351

It works here, see the attached video. Do you have PhpStorm's "Max. simultaneous connections" set to something higher than "1"?

debug.webm (1,139,187 bytes)

samuel.nogueira

2020-03-25 15:46

reporter   ~0005352

Yup, during both tests 'Max. simultaneous connections' was set to 3.
However, your video showed what I was doing wrong, my PhpStorm was not listening for new connections, so it refused the incoming connection from the child process, and that is why I wasn't able to step-debug the forked process.
My confusing came from the fact that this wasn't needed in versions 2.6.1 and below.
Apologies for taking your time to make me see this, I hope at least someone finds this useful, I know my team will.

For me, issue can be closed, there is no problem after all.

Thank you!

derick

2020-03-25 15:59

administrator   ~0005353

Ah, I see that in your log now:

[1] <- run -i 12
[9] Log closed at 2020-03-25 15:10:37

[9] Log opened at 2020-03-25 15:10:37
[9] I: Connecting to configured address/port: 172.17.0.1:9000.
[9] W: Creating socket for '172.17.0.1:9000', poll success, but error: Operation now in progress (29).
[9] E: Could not connect to client. :-(
[9] Log closed at 2020-03-25 15:10:37


Before Xdebug 2.7, it only worked by chance. Both parent and child would share the same connection, and if data got out of sync in any way, which was quite easy to occur, the debugger would get mega confused. With the fixing of 0000938, it now makes a new connection per child.

If you and your team like it, perhaps you can support me working on Xdebug ;-) -> https://xdebug.org/support

Issue History

Date Modified Username Field Change
2020-03-24 18:55 samuel.nogueira New Issue
2020-03-24 18:55 samuel.nogueira File Added: Dockerfile
2020-03-24 18:55 samuel.nogueira File Added: script.php
2020-03-24 18:55 samuel.nogueira File Added: xdebug.log
2020-03-24 18:58 samuel.nogueira Note Added: 0005346
2020-03-25 11:09 derick Assigned To => derick
2020-03-25 11:09 derick Status new => feedback
2020-03-25 11:09 derick Note Added: 0005347
2020-03-25 11:58 samuel.nogueira File Added: Screencast from 25-03-2020 11:44:08.webm
2020-03-25 11:58 samuel.nogueira File Added: xdebug261.log
2020-03-25 11:58 samuel.nogueira File Added: xdebug261.Dockerfile
2020-03-25 11:58 samuel.nogueira Note Added: 0005348
2020-03-25 11:58 samuel.nogueira Status feedback => assigned
2020-03-25 12:05 derick Status assigned => feedback
2020-03-25 12:06 derick Note Added: 0005349
2020-03-25 15:13 samuel.nogueira File Added: xdebug-2.log
2020-03-25 15:13 samuel.nogueira File Added: script-2.php
2020-03-25 15:13 samuel.nogueira File Added: Screencast from 25-03-2020 15:10:32.webm
2020-03-25 15:13 samuel.nogueira Note Added: 0005350
2020-03-25 15:13 samuel.nogueira Status feedback => assigned
2020-03-25 15:25 derick File Added: debug.webm
2020-03-25 15:25 derick Note Added: 0005351
2020-03-25 15:46 samuel.nogueira Note Added: 0005352
2020-03-25 15:59 derick Status assigned => resolved
2020-03-25 15:59 derick Resolution open => no change required
2020-03-25 15:59 derick Note Added: 0005353