Skip to content

Request making a second request makes it hang #164

Closed

Description

@jonyo

For a project, we have multiple micro services, running in different containers each set up with it's own xdebug port so I can debug a specific micro service or multiple microservices at once. Everything is working well, breakpoints break, code is able to step properly etc. Unless one microservice makes a call to another one that makes a call back to the first micro service, at which point it hangs until the connection times out.

Before it times out though, in the editor it shows 2 requests on the call stack. If I put a breakpoint in the code in "container A" before the point it makes that call to container B, it breaks just fine. If I then try to step through it, it hangs once it gets to the line that makes the call to container B until the container B call times out, then it continues on with a timeout error creating a stop point in xdebug.

I was able to simplify the error down to a simple test not involving multiple containers or anything, basically just have a call make a curl connection to make a second call.

PHP version: 5.6.30
XDebug version: 2.5.0
Adapter version: 1.10.0

Your launch.json:

{
	"version": "0.2.0",
	"configurations": [
		{
			"name": "Listen for XDebug",
			"type": "php",
			"request": "launch",
			"port": 9002,
			"localSourceRoot": "${workspaceRoot}",
			"serverSourceRoot": "/var/www/public/releases/local_source"
		}
	]
}

XDebug php.ini config:

zend_extension=xdebug.so
[xdebug]
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.remote_mode=req
xdebug.remote_port=9002
xdebug.remote_host=10.55.55.1

XDebug logfile (from setting xdebug.remote_log in php.ini):

Log opened at 2017-05-15 17:02:39
I: Connecting to configured address/port: 10.55.55.1:9002.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/public/releases/local_source/app/webroot/test2.php" language="PHP" xdebug:language_version="5.6.30-1+deb.sury.org~xenial+1" protocol_version="1.0" appid="26056"><engine version="2.5.0"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2016 by Derick Rethans]]></copyright></init>

<- breakpoint_list -i 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="1"></response>

<- breakpoint_set -i 2 -t line -f file:///var/www/public/releases/local_source/app/webroot/test2.php -n 10
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="2" id="260560003"></response>

<- breakpoint_list -i 3
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="3"><breakpoint type="line" filename="file:///var/www/public/releases/local_source/app/webroot/test2.php" lineno="10" state="enabled" hit_count="0" hit_value="0" id="260560003"></breakpoint></response>

<- breakpoint_list -i 4
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="4"><breakpoint type="line" filename="file:///var/www/public/releases/local_source/app/webroot/test2.php" lineno="10" state="enabled" hit_count="0" hit_value="0" id="260560003"></breakpoint></response>

<- breakpoint_set -i 5 -t exception -x *
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="5" id="260560004"></response>

<- run -i 6
Log opened at 2017-05-15 17:02:39
I: Connecting to configured address/port: 10.55.55.1:9002.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/public/releases/local_source/app/webroot/test2.php" language="PHP" xdebug:language_version="5.6.30-1+deb.sury.org~xenial+1" protocol_version="1.0" appid="26052"><engine version="2.5.0"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2016 by Derick Rethans]]></copyright></init>

<- breakpoint_list -i 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="1"></response>

<- breakpoint_set -i 2 -t line -f file:///var/www/public/releases/local_source/app/webroot/test2.php -n 10
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="2" id="260520005"></response>

<- stop -i 3
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="stop" transaction_id="3" status="stopped" reason="ok"></response>

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="6" status="stopping" reason="ok"></response>

<- breakpoint_list -i 7
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="7"><breakpoint type="line" filename="file:///var/www/public/releases/local_source/app/webroot/test2.php" lineno="10" state="enabled" hit_count="0" hit_value="0" id="260560003"></breakpoint><breakpoint type="exception" state="enabled" hit_count="0" hit_value="0" id="260560004"></breakpoint></response>

<- stop -i 8
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="stop" transaction_id="8" status="stopped" reason="ok"></response>

Log closed at 2017-05-15 17:02:48

Adapter logfile (from setting "log": true in launch.json):

<- launchResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 2,
  command: 'launch',
  success: true }
new connection 1
<- threadEvent
ThreadEvent {
  seq: 0,
  type: 'event',
  event: 'thread',
  body: { reason: 'started', threadId: 1 } }
<- initializedEvent
InitializedEvent { seq: 0, type: 'event', event: 'initialized' }
-> threadsRequest
{ command: 'threads', type: 'request', seq: 3 }
<- threadsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 3,
  command: 'threads',
  success: true,
  body: { threads: [ Thread { id: 1, name: 'Request 1 (1:02:39 PM)' } ] } }
-> setBreakpointsRequest
{ command: 'setBreakpoints',
  arguments: 
   { source: 
      { path: '/Users/jonathanfoote/zumba/git/public/app/webroot/test2.php',
        name: 'test2.php' },
     lines: [ 10 ],
     breakpoints: [ { line: 10 } ],
     sourceModified: false },
  type: 'request',
  seq: 4 }
<- setBreakpointsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 4,
  command: 'setBreakpoints',
  success: true,
  body: { breakpoints: [ { verified: true, line: 10 } ] } }
-> setFunctionBreakpointsRequest
{ command: 'setFunctionBreakpoints',
  arguments: { breakpoints: [] },
  type: 'request',
  seq: 5 }
<- setFunctionBreakpointsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 5,
  command: 'setFunctionBreakpoints',
  success: true,
  body: { breakpoints: [] } }
-> setExceptionBreakpointsRequest
{ command: 'setExceptionBreakpoints',
  arguments: { filters: [ '*' ] },
  type: 'request',
  seq: 6 }
<- setExceptionBreakpointsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 6,
  command: 'setExceptionBreakpoints',
  success: true }
-> configurationDoneRequest
{ command: 'configurationDone', type: 'request', seq: 7 }
-> threadsRequest
{ command: 'threads', type: 'request', seq: 8 }

<- threadsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 8,
  command: 'threads',
  success: true,
  body: { threads: [ Thread { id: 1, name: 'Request 1 (1:02:39 PM)' } ] } }
new connection 2
<- threadEvent
ThreadEvent {
  seq: 0,
  type: 'event',
  event: 'thread',
  body: { reason: 'started', threadId: 2 } }
<- initializedEvent
InitializedEvent { seq: 0, type: 'event', event: 'initialized' }
-> threadsRequest
{ command: 'threads', type: 'request', seq: 9 }
<- threadsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 9,
  command: 'threads',
  success: true,
  body: 
   { threads: 
      [ Thread { id: 1, name: 'Request 1 (1:02:39 PM)' },
        Thread { id: 2, name: 'Request 2 (1:02:39 PM)' } ] } }
-> setBreakpointsRequest
{ command: 'setBreakpoints',
  arguments: 
   { source: 
      { path: '/Users/jonathanfoote/zumba/git/public/app/webroot/test2.php',
        name: 'test2.php' },
     lines: [ 10 ],
     breakpoints: [ { line: 10 } ],
     sourceModified: false },
  type: 'request',
  seq: 10 }
-> disconnectRequest
{ command: 'disconnect',
  arguments: { restart: false },
  type: 'request',
  seq: 11 }
<- configurationDoneResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 7,
  command: 'configurationDone',
  success: true }
<- outputEvent
OutputEvent {
  seq: 0,
  type: 'event',
  event: 'output',
  body: { category: 'console', output: 'connection 1 closed\n' } }
connection 1 closed
<- threadEvent
ThreadEvent {
  seq: 0,
  type: 'event',
  event: 'thread',
  body: { reason: 'exited', threadId: 1 } }
-> setFunctionBreakpointsRequest
{ command: 'setFunctionBreakpoints',
  arguments: { breakpoints: [] },
  type: 'request',
  seq: 12 }

Code snippet to reproduce:

<?php

if (empty($_GET['connect'])) {
	$ch = curl_init('http://localhost/' . $_SERVER['REQUEST_URI'] . '?connect=1');
	curl_exec($ch);
	curl_close($ch);
	die ('end of initial call');
}

phpinfo();

Activity

  1. SarnaMC commented on Oct 24, 2017

    @SarnaMC

    Have the same problem

  2. ZurabWeb commented on Oct 24, 2017

    @ZurabWeb

    This is really annoying, the browser tab just hangs and time out if there are parallel requests to the same app. I really hope it's fairly simple to fix...

  3. SarnaMC commented on Oct 24, 2017

    @SarnaMC

    @ZurabWeb yes, me too, but look at issue open time. 15 May. 5 months :(

  4. ZurabWeb commented on Oct 24, 2017

    @ZurabWeb

    @SarnaMC I think it didn't get the attention of the author. Maybe with more comments we could draw their attention.

  5. felixfbecker commented on Oct 24, 2017

    @felixfbecker
    Contributor

    I get a notification for every comment and more comments won't fix the issue ;)
    I don't have the capacity to look into this and it might not even be a bug in the adapter. If you care about this why not look into it yourself? It's open source ⭐️

  6. jonyo commented on Oct 24, 2017

    @jonyo
    ContributorAuthor

    @felixfbecker Maybe you already noticed this but to me, it looks like on the second request, it attempts to send the breakpoints, and is hung before it gets a response. Looking at the code, if I'm reading it correctly it looks like it attempts to send the breakpoints to all connections. I wonder if it tries to send it to the initial connection which is paused so is not going to respond...

    I was going to test this theory but can't seem to get the extension set up for debugging, it keeps telling me Debug adapter process has terminated unexpectedly when I try to start the debugger in the VSC extension debug window.

  7. felixfbecker commented on Oct 24, 2017

    @felixfbecker
    Contributor

    That could very well be the problem.

    I have not debugged this extension in a long time, the config might have changed. What config did you use exactly? Did you follow the contribution guide?

  8. calebporzio commented on Oct 24, 2017

    @calebporzio

    @jonyo - I'm working on a project that uses microservices and this is a deal breaker for me too - hope you figure something out.

  9. jonyo commented on Oct 24, 2017

    @jonyo
    ContributorAuthor

    @felixfbecker

    What config did you use exactly?

    For debugging the extension, used the "launch extension" config:

        {
          "name": "Launch Extension",
          "type": "extensionHost",
          "request": "launch",
          "runtimeExecutable": "${execPath}",
          "args": ["--extensionDevelopmentPath=${workspaceRoot}"],
          "sourceMaps": true,
          "outDir": "${workspaceRoot}/out"
        }
    

    Did you follow the contribution guide?

    I tried to as close as possible, ran into a few issues I am not sure about:

    code testproject --extensionDevelopmentPath=.

    When I try this it gives some errors:

    [.fseventsd]: Cannot read file .fseventsd/package.json: EACCES: permission denied, open '.fseventsd/package.json'.
    Close
    Error[.Spotlight-V100]: Cannot read file .Spotlight-V100/package.json: EACCES: permission denied, open '.Spotlight-V100/package.json'.
    Close
    Error[.PKInstallSandboxManager-SystemSoftware]: Cannot read file .PKInstallSandboxManager-SystemSoftware/package.json: EACCES: permission denied, open '.PKInstallSandboxManager-SystemSoftware/package.json'.
    

    I was able to just open the test project using the menus but not sure if that sets it up correctly.

    Here's a quick screencast:

    https://screencast.com/t/8pqRSIq9iEBy

  10. felixfbecker commented on Oct 24, 2017

    @felixfbecker
    Contributor

    That sounds very weird to me. What npm/node version are you running? Did you try a git clean fresh npm install?

  11. jonyo commented on Oct 24, 2017

    @jonyo
    ContributorAuthor
    $ node --version
    v8.7.0
    $ npm --version
    5.4.2
    

    I tried fresh npm install and typings install as well.

    I wonder if it is something to do with the outDir, I get a warning that is deprecated in favor of outFiles.

    This is on macOS 10.13 High Sierra if that makes a difference.

  12. felixfbecker commented on Oct 24, 2017

    @felixfbecker
    Contributor

    You need to use the Node version that VS Code uses, which is v7.
    A good reference is always the CI config:
    https://github.com/felixfbecker/vscode-php-debug/blob/ed5a99d0d4a5e6840186c21890b7027901609b2e/.travis.yml#L14

  13. jonyo commented on Oct 24, 2017

    @jonyo
    ContributorAuthor

    @felixfbecker
    Did that, same result... Then I looked at the rest of the travis config and noticed this line...

    https://github.com/felixfbecker/vscode-php-debug/blob/ed5a99d0d4a5e6840186c21890b7027901609b2e/.travis.yml#L22

    Ran that, now it's working. 👍 Will report back if I find a solution to the multiple call issue.

  14. SarnaMC commented on Oct 25, 2017

    @SarnaMC

    My configuration (use xdebug)
    { "name": "Listen for XDebug", "type": "php", "log": true, "request": "launch", "port": 9000 }

    Last log in Debug Console:
    -> setBreakpointsRequest { command: 'setBreakpoints', arguments: { source: { path: '/var/www/html/drupal/drupal7/htdocs/sites/all/themes/contrib/my-theme/templates/search/blocks/block--views---exp-search-custom-article-page.tpl.php', name: 'block--views---exp-search-custom-article-page.tpl.php' }, lines: [ 2 ], breakpoints: [ { line: 2 } ], sourceModified: false }, type: 'request', seq: 14 }

    The path is good, and debugging work on Atom so xdebug works

  15. 19 remaining items

  16. jonyo commented on Aug 14, 2018

    @jonyo
    ContributorAuthor

    Got it working! I'll make a PR to fix.

    So, when you send the run command (or step into, etc), xdebug basically doesn't do anything on that socket connection until it hits a breakpoint or the next line is run or whatever. So if the code it is running hangs up, say you add a sleep(30) and it runs that line... you won't get a response until that code is done.

    In this scenario described, a new connection is being made during that time it is hung up running PHP code. When there is a new connection, vscode makes requests that basically reset all the breakpoints. But the way it is coded, it attempts to set the breakpoints on ALL connections and it waits for the results of all those calls. For the first connection, it ends up adding those calls to the queue, but it never gets to run them because it's waiting on that curl request, which is waiting on breakpoint calls... So it gets deadlocked.

  17. felixfbecker commented on Aug 14, 2018

    @felixfbecker
    Contributor

    @jonyo Awesome work!

  18. felixfbecker commented on Aug 28, 2018

    @felixfbecker
    Contributor

    🎉 This issue has been resolved in version 1.12.5 🎉

    The release is available on GitHub release

    Your semantic-release bot 📦🚀

  19. sabman3 commented on Aug 28, 2018

    @sabman3

    I know you said this was fixed in the latest release, but I'm not sure it is. I have two ajax calls for a page going to server. I see two process running in the debug window, however sometimes it does stop on the breakpoints while at other times it doesn't. Then on top of that even if I tell it to finish and the processes go away from the debug window, the browser freezes until I stop the debug.

    {
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
    {
    "name": "Listen for XDebug",
    "type": "php",
    "request": "launch",
    "port": 9000,
    "stopOnEntry": true,
    "xdebugSettings": {
    "max_children": 20
    }
    }
    ]
    }

  20. yavgech commented on Sep 2, 2018

    @yavgech

    It now hangs when receiving a second Ajax request. My web page sends Ajax requests continuously.
    Downgraded to version 1.12.4 and now it works great again.

  21. devnix commented on Aug 2, 2019

    @devnix

    For me, it hangs too when receiving an AJAX request. Still didn't try to downgrade.

  22. Zelfapp commented on Sep 4, 2019

    @Zelfapp

    Running v 1.3.8.0

    Any time there are 2 or more ajax calls php debugging hangs. Had to switch from vscode to phpstorm so I could debug. I didn't make any changes. Phpstorm works, vscode does not.

    image

  23. jonyo commented on Sep 4, 2019

    @jonyo
    ContributorAuthor

    @Zelfapp By the way that sounds like a different issue, this one was a deadlock that happened when one request made a second request, it was not related to multiple ajax requests.

    Also this one was resolved and closed over a year ago, you may get more traction creating a new issue or looking for a more recent issue that involves multiple ajax requests.

    I see the confusion though if you only read the issue title it does sound related; since you are not the first to comment on it I'll update the title (if it lets me).

  24. changed the title [-]Multiple calls make it hang[/-] [+]Request making its own second request makes it hang[/+] on Sep 4, 2019
  25. changed the title [-]Request making its own second request makes it hang[/-] [+]Request making a second request makes it hang[/+] on Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions