xdebug / vscode-php-debug

PHP Debug Adapter for Visual Studio Code 🐞⛔
MIT License
780 stars 178 forks source link

PROXY ERROR: Client for 'VSCODE' is already connected error #856

Closed asffafafsaasgagsga closed 1 year ago

asffafafsaasgagsga commented 1 year ago

PHP version: 7.0.28 Xdebug version: 2.8.1 VS Code extension version: v1.29.0

Your launch.json: { "version": "0.2.0", "configurations": [ { "name": "Listen for Xdebug", "type": "php", "request": "launch", "port": 15224, "pathMappings": { "/path/": "${workspaceFolder}", }, "proxy":{ "enable":true, "host": "xxx.xxx.xxx.xxx", "port": x, "key": "VSCODE", "timeout": 3000, "allowMultipleSessions": false } } ] }

I am using vscode-php-debug extension in vscode.

The proxy was successfully connected through the ide key.

However, when I received the PROXY ERROR: Client for 'VSCODE' is already connected error, I restarted the proxy server

The error show up when I ran the vscode window reload command.

Is there any way I can cope without restarting the proxy server at this time?

zobo commented 1 year ago

The adapter will unregister from the proxy when the session is stopped. If vscode and php-debug are somehow interrupted this will not take place and the proxy will keep the IDE association and startup will fail. This is sadly by design.

You could send a proxystop -k VSCODE command to the proxy via telnet, nc or similar command line tools.

I was planning on adding a vscode command that you could call, just have not gotten to it. I personally never use the proxy, so it wasn't high on my list.

asffafafsaasgagsga commented 1 year ago

I tried several attempts to send a command like "proxystop -k VSCODE"

The command list I tried is

echo "proxystop -k VSCODE" $ echo . | ncat 127.0.0.1 9003 echo "proxystop -k VSCODE" > /dev/tcp/127.0.0.1/9003

but doesn't work properly.

could you give me some example commands that could be successfully executed?

my DBGp proxy information is below

Xdebug DBGp proxy (0.4.2-dev) Copyright 2020 by Derick Rethans

jnagler commented 1 year ago

Default for Xdebug within PHP is to connect to 9003 and normally a debugging client is listening/waiting for debug info on the port. DBGp proxy takes the role of the client so it listen on 9003 as default. On the other side the default for the DBGp proxy to listening for IDE/clients is on 9001 which includes providing the proxy commands. Therefore sending to 9003 may be the one issue.

A second may be that IIRC the commands need to be NULL terminated strings which we do in the following was:

echo -e "proxyinit -p CLIENTPORT -k IDEKEY -m 1\0" | nc 127.0.0.1 9001 echo -e "echo -e "proxystop -k IDEKEY\0" | nc 127.0.0.1 9001

zobo commented 1 year ago

Yes, I think it's the NULL characted.

echo -e "proxystop -k VSCODE\0" | nc 127.0.0.1 9001

Check that you use the right port - the one for IDEs not the one for Xdebug.

asffafafsaasgagsga commented 1 year ago

Thank you so much! The issue was solved.

I solved it by the command below.

echo -e "proxystop -k VSCODE\0" | nc 127.0.0.1 9003

my launch.json was

{ "version": "0.2.0", "configurations": [ { "name": "Listen for Xdebug", "type": "php", "request": "launch", "port": 15224, "pathMappings": { "/path/": "${workspaceFolder}", }, "proxy":{ "enable":true, "host": "x.x.x.x", "port": 9003, "key": "VSCODE", "timeout": 3000, "allowMultipleSessions": false } } ] }

and i send to 9003 port and It properly work for remove connection that has specific ide key.