Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stuck in "Psalm: starting" #1

Closed
shaneparsons opened this issue Jun 22, 2022 · 33 comments
Closed

Stuck in "Psalm: starting" #1

shaneparsons opened this issue Jun 22, 2022 · 33 comments

Comments

@shaneparsons
Copy link

shaneparsons commented Jun 22, 2022

I followed the setup steps to the best of my ability, but the extension is stuck in a "Psalm: starting" state... Here's my config:

settings.json
  "psalm_docker.dockerServiceName": "dme-app",
  "psalm_docker.localDockerComposePaths": [
    "/home/sparsons/repo/dme/docker-compose.override.yml",
    "/home/sparsons/repo/dme/docker-compose.yml"
  ],
  "psalm_docker.remotePsalmServerPath": "/var/www/html/vendor/bin/psalm-language-server",
  "psalm_docker.localPath": "/home/sparsons/repo/dme",
  "psalm_docker.remotePath": "/var/www/html/",
  "psalm_docker.remotePsalmXmlPath": "/var/www/html/psalm.xml",
  "psalm_docker.debug": true,

Some more details about my environment:

  • PHP (8.1.7) is running in a container called dme-app (details below)
  • Psalm (4.23) and Xdebug (3.1.5) are both running / working in that container
  • psalm / psalm-language-server / psalm.xml are present both locally and in the container
    • I'm wondering if this is part of the problem? i.e. maybe the plugin is trying to use the local versions?
  • The directory I want to scan is the src/ directory (i.e. ./vendor/bin/psalm src/), which is also in that container
docker-compose (relevent parts)

main:

dme-app:
  image: sunteck/dme:dev
  build:
    context: ./
    dockerfile: ./Dockerfile
  volumes:
    - ./:/var/www/html/

override:

dme-app:
  volumes:
    - .vscode/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
    - .vscode/xdebug.log:/var/log/xdebug.log
  extra_hosts:
    - host.docker.internal:host-gateway
dockerfile (relevent parts)
FROM php:8.1-fpm as base

RUN apt-get update && \
    apt-get install -y libpq-dev libxslt-dev

RUN docker-php-ext-install intl opcache xsl pgsql pdo_pgsql sockets
RUN pecl install redis \
    && docker-php-ext-enable redis

COPY . /var/www/html
COPY ./provision/php/memory.ini /usr/local/etc/php/conf.d/
COPY --from=assets /app/public/build/ /var/www/html/public/build/
COPY --from=composer /app/vendor/ /var/www/html/vendor/

RUN mkdir -p public/bundles/ && ./bin/console assets:install
composer.json (relevent parts)
"psalm/plugin-phpunit": "^0.16.1",
"psalm/plugin-symfony": "^3.1",
"vimeo/psalm": "^4.22",
"weirdan/doctrine-psalm-plugin": "^2.3"

I'm not sure if I just have part of my config wrong, or if something else is not set up right? Psalm does work outside of this plugin, so environment wise everything is good.

I recently set up a similar phpstan plugin by using a binCommand parameter:

settings.json
"phpstan.binCommand": ["php-dme", "vendor/bin/phpstan"],
"phpstan.paths": { "/home/sparsons/repo/dme": "/var/www/html" },

php-dme is a bin command for docker-compose run --rm dme-app "$@"

Perhaps we need something like that here as well? Maybe something like this already exists and I'm just missing it?

Any help would be greatly appreciated!

@plotbox-io
Copy link
Owner

plotbox-io commented Jun 22, 2022

Hi Shane, thanks for your feedback. I've only recently forked this project to get it working for my company so you are one of the first to try it outside of our specific case. I'm happy to work with you to try and get it working for your app too.

On looking into this, I see that my assumption about the debug mode was incorrect. It was only showing output when actually debugging the extension, which isn't very useful for the end-user. I've pushed an update to fix that. Debug output should now show in the Output tool window. So now you should get useful info about why it is not working to narrow things down.

Add this to your settings.json to enable debug output:

"psalm_docker.debug": true

Also in the update (1.0.3) I've:

  • Added comments to improve the readme instructions
  • Added setting "psalm_docker.dockerHostDomainOrIp" to allow configuring of the way docker talks back to the host (rather than assuming 'host.docker.internal' is available to use)

Let me know if any of this helps to narrow in on the cause of the issue

Kind regards,
Richard

@plotbox-io
Copy link
Owner

Sorry, seems to be slow to publish the new version to VSCode marketplace today. Still listed as 1.0.2. Has pushed but not yet reflected. Should be available shortly all being well

@shaneparsons
Copy link
Author

@plotbox-io Thanks for the quick response! I'll keep my eye out for the new version and will update once I've retested.

@plotbox-io
Copy link
Owner

No problem @shaneparsons. I've actually ended up bumping a couple versions to get it resolved (now at 1.0.5). It was being blocked in the extension verification step as I had added a shortUrl in the readme.md and was detected as suspicious. Anyway, should be sorted now :D

@shaneparsons
Copy link
Author

The added logging is definitely helpful:

localUriPath: file:///home/sparsons/repo/dme

remoteUriPath: file:///var/www/html

psalm_docker.localDockerComposePaths: /home/sparsons/repo/dme/docker-compose.override.yml,/home/sparsons/repo/dme/docker-compose.yml

psalm_docker.remotePsalmServerPath: /var/www/html/vendor/bin/psalm-language-server

psalm_docker.localPath: /home/sparsons/repo/dme

psalm_docker.remotePath: /var/www/html

psalm_docker.remotePsalmXmlPath: /var/www/html/psalm.xml

psalm_docker.dockerServiceName: dme-app

vscode server is listening on 127.0.0.1: 37125

starting psalm server: docker-compose -f /home/sparsons/repo/dme/docker-compose.override.yml -f /home/sparsons/repo/dme/docker-compose.yml exec -T dme-app php -d xdebug.start_with_request=no -f /var/www/html/vendor/bin/psalm-language-server -- -c /var/www/html/psalm.xml -r /var/www/html --find-dead-code --verbose --tcp=host.docker.internal:37125

server process stderr: Uncaught RuntimeException: PHP Error: stream_socket_client(): Unable to connect to tcp://host.docker.internal:37125 (Connection timed out) in /var/www/html/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php:469 in /var/www/html/vendor/vimeo/psalm/src/Psalm/Internal/ErrorHandler.php:66
Stack trace:
#0 [internal function]: Psalm\Internal\ErrorHandler::Psalm\Internal\{closure}(2, 'stream_socket_c...', '/var/www/html/v...', 469)
#1 /var/www/html/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(469): stream_socket_client('tcp://host.dock...', 0, '')
#2 /var/www/html/vendor/vimeo/psalm/src/Psalm/Internal/Cli/LanguageServer.php(321): Psalm\Internal\Analyzer\ProjectAnalyzer->server('host.docker.int...', false)
#3 /var/www/html/vendor/vimeo/psalm/psalm-language-server(7): Psalm\Internal\Cli\LanguageServer::run(Array)
#4 /var/www/html/vendor/bin/psalm-language-server(117): include('/var/www/html/v...')
#5 {main}
(Psalm 4.23.0@f1fe6ff483bf325c803df9f510d09a03fd796f88 crashed due to an uncaught Throwable)

@plotbox-io
Copy link
Owner

plotbox-io commented Jun 22, 2022

OK so it looks like the docker container is unable to talk to the host via the special domain host.docker.internal. That domain isn't available by default - it requires a bit of setup to put in place (see the updated Readme.md). If your docker services are using the default network (they probably are) you can change your psalm_docker.dockerHostDomainOrIp setting to "172.17.0.1" (see here).

Alternatively, to make host.docker.internal work, see the config that's needed on your docker-compose.yml file(s):
https://stackoverflow.com/questions/48546124/what-is-linux-equivalent-of-host-docker-internal/67158212#67158212

To debug further, you can bash in to the docker container (something like docker compose exec php bash assuming your service is called 'php'). Then you could use ping to test if you can talk to the host through a particular IP or domain (i.e., ping host.docker.internal or ping 172.17.0.1). If using the default network, you should get a response from 172.17.0.1. If ping is not available you may need to install it; on debian based image it would be apt-get install -y iputils-ping to do that.

Let me know if that helps!

@shaneparsons
Copy link
Author

shaneparsons commented Jun 22, 2022

I can ping that ip fine

root@40d8a2e3e17f:/var/www/html# ping 172.17.0.1
PING 172.17.0.1 (172.17.0.1) 56(84) bytes of data.
64 bytes from 172.17.0.1: icmp_seq=1 ttl=64 time=0.220 ms
64 bytes from 172.17.0.1: icmp_seq=2 ttl=64 time=0.061 ms

But if if try adding the 38451 port that gets appended in the command it fails (maybe this is inevitable?):

root@40d8a2e3e17f:/var/www/html# ping 172.17.0.1:38451
ping: 172.17.0.1:38451: Name or service not known

Is there anything I need to do to expose that port, or anything along the lines?

EDIT: that second use of ping wasn't valid...

@shaneparsons
Copy link
Author

shaneparsons commented Jun 22, 2022

Yeah, it's definitely that tcp part that's causing the issue here... Running the command manually just hangs:

docker-compose -f /home/sparsons/repo/dme/docker-compose.override.yml -f /home/sparsons/repo/dme/docker-compose.yml exec -T dme-app php -d xdebug.start_with_request=no -f /var/www/html/vendor/bin/psalm-language-server -- -c /var/www/html/psalm.xml -r /var/www/html/src --find-dead-code --verbose --tcp=172.17.0.1:38231

But if I remove --tcp=172.17.0.1:38231 it seems to maybe work (or at least not fail)?

docker-compose -f /home/sparsons/repo/dme/docker-compose.override.yml -f /home/sparsons/repo/dme/docker-compose.yml exec -T dme-app php -d xdebug.start_with_request=no -f /var/www/html/vendor/bin/psalm-language-server -- -c /var/www/html/psalm.xml -r /var/www/html/src --find-dead-code --verbose
Content-Type: application/vscode-jsonrpc; charset=utf8
Content-Length: 186

{"jsonrpc":"2.0","method":"window\/logMessage","params":{"type":4,"message":"[Psalm 4.23.0@f1fe6ff483bf325c803df9f510d09a03fd796f88 - PHP Language Server] Language server has started."}}

@plotbox-io
Copy link
Owner

Hi again Shane. I'm out of office today so not at a PC but here's my thoughts:

  • Great that you can ping the IP!
  • The port number is randomised from available ports
  • The extension, on boot, will set up a listener on that random port that Psalm will talk to in the language server / JSON RPC format
  • It shouldn't be necessary to open ports on your host so docker can talk to it. In my experience the docker container can access any port on the host so long as you can ping it. It could be though that there is some network configuration I'm unaware of that could make this more restrictive..
  • Might be worth checking docker is up to date and reboot the machine if it hasn't been in a while (i.e., if usually just put in sleep mode). Worth ruling it out at least..

I'll be back in the office tomorrow so can have a proper think through this. Let me know if you find anything else out. Thanks for your patience in working through this, will be good to make the extension more robust for others.

Kind regards,
Richard

@shaneparsons
Copy link
Author

shaneparsons commented Jun 23, 2022

Hey Richard, sounds good. It might also be worth mentioning that the host machine I'm on is actually a remote Linux server that I access through SSH. Shouldn't make a difference in the end, but maybe there's a slight difference as far as ports go, or something else along the lines...

I do use the built in remote SSH plugin though, so it's as if I'm on the machine directly.

@plotbox-io
Copy link
Owner

It does sound on the surface quite likely that the fact you are running via a remote linux server is related to the problem. To make sure I understand fully (so I can replicate):

  1. You are running VSCode on your host computer (what host OS out of interest?).
  2. You are using the VSCode extension 'Remote - SSH' by Microsoft to start VScode up pointing at the linux box you run things on.
  3. The remote linux box has docker installed and is where the container(s) live when running
  4. You test the web-server from your host computer by accessing an accessbile port forwarded both by the container and also the remote (virtual?) linux box

Does that sound correct?

@plotbox-io
Copy link
Owner

Hi again Shane. So I did a bit of experimenting with the assumptions listed in my last comment (running VSCode in 'remote ssh mode' to a virtual machine over an exposed SSH port) and it seemed to work without any real issues. The remote machine had to have:

  1. Docker engine installed (I used community edition install described here)
  2. docker-compose installed
  3. The app needs to be already 'spun up' with docker-compose up before starting up VSCode

As I hit each of the above, I added some better debugging output for when the docker-compose sub-command fails so we get some error output rather than silence in these failure scenarios. I've pushed a new version (1.0.6) with the added debug output - please could you try again with it and let me know if you see any errors?

Kind regards

@shaneparsons
Copy link
Author

shaneparsons commented Jun 24, 2022

Hey Richard, here's the output from the latest attempt:

Output
localUriPath: file:///home/sparsons/repo/dme

remoteUriPath: file:///var/www/html/src

psalm_docker.localDockerComposePaths: /home/sparsons/repo/dme/docker-compose.override.yml,/home/sparsons/repo/dme/docker-compose.yml

psalm_docker.remotePsalmServerPath: /var/www/html/vendor/bin/psalm-language-server

psalm_docker.localPath: /home/sparsons/repo/dme

psalm_docker.remotePath: /var/www/html/src

psalm_docker.remotePsalmXmlPath: /var/www/html/psalm.xml

psalm_docker.dockerServiceName: dme-app

vscode server is listening on 0.0.0.0: 43033

starting psalm server: docker-compose -f /home/sparsons/repo/dme/docker-compose.override.yml -f /home/sparsons/repo/dme/docker-compose.yml exec -T dme-app php -d xdebug.start_with_request=no -f /var/www/html/vendor/bin/psalm-language-server -- -c /var/www/html/psalm.xml -r /var/www/html/src --find-dead-code --verbose --tcp=172.17.0.1:43033

server process stderr: Uncaught RuntimeException: PHP Error: stream_socket_client(): Unable to connect to tcp://172.17.0.1:43033 (Connection timed out) in /var/www/html/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php:469 in /var/www/html/vendor/vimeo/psalm/src/Psalm/Internal/ErrorHandler.php:66
Stack trace:
#0 [internal function]: Psalm\Internal\ErrorHandler::Psalm\Internal\{closure}(2, 'stream_socket_c...', '/var/www/html/v...', 469)
#1 /var/www/html/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(469): stream_socket_client('tcp://172.17.0....', 0, '')
#2 /var/www/html/vendor/vimeo/psalm/src/Psalm/Internal/Cli/LanguageServer.php(321): Psalm\Internal\Analyzer\ProjectAnalyzer->server('172.17.0.1:4303...', false)
#3 /var/www/html/vendor/vimeo/psalm/psalm-language-server(7): Psalm\Internal\Cli\LanguageServer::run(Array)
#4 /var/www/html/vendor/bin/psalm-language-server(117): include('/var/www/html/v...')
#5 {main}
(Psalm 4.23.0@f1fe6ff483bf325c803df9f510d09a03fd796f88 crashed due to an uncaught Throwable)


Error: docker-compose sub-command exited with error code 1

Looking further into the error now...

As far as my environment goes:

  1. You are running VSCode on your host computer (what host OS out of interest?).
    macOS 12.3.1
  2. You are using the VSCode extension 'Remote - SSH' by Microsoft to start VScode up pointing at the linux box you run things on.
    Correct. We'll call this "the box" going forward.
  3. The remote linux box has docker installed and is where the container(s) live when running
    Correct
  4. You test the web-server from your host computer by accessing an accessbile port forwarded both by the container and also the remote (virtual?) linux box
    The box uses an nginx proxy to expose the various apps. That paired w/ some /etc/host entries is how I access the web portion from outside of the box, in the browser. Nothing other than the web is accessed directly from outside of the box, and vice versa. Everything is completely contained in the box.

The box is hosted on AWS and is always running. I simply just tap into it when I launch vscode or ssh in.

Let me know if you need further clarification on anything!

@shaneparsons
Copy link
Author

Perhaps this is an upstream issue? Maybe related to psalm/psalm-vscode-plugin#176 (comment)?

@plotbox-io
Copy link
Owner

plotbox-io commented Jun 24, 2022

Thanks Shane.

OK so it's still the issue with the container unable to talk to the listener (running on the box). It's odd because we've already seen that we can ping the box IP from inside the box container. So it has to be either:

  1. The container unable to communicate out of the container through a port
  2. The extension receiver not really listening on the port as expected
  3. The medium between (i.e., the docker engine or linux) blocking the communication

(Could you just double check that you ran the ping 172.17.0.1 from inside the container and not just on the box. I noticed that the ping does also resolve when running on the VM box itself so thought it was worth double checking)

Let's see if we can rule some out to narrow things down...

Possibility 1
Firstly, the ability of the container to 'talk' to an open port on the box:

  • On the box: Install socat with sudo apt install socat
  • On the box: Run socat -v tcp-l:12233,fork exec:'/bin/cat' to start a simple 'echo server'
  • Bash inside your running docker container with something like docker-compose exec php bash (assuming php is the main service name)
  • Install ncat inside container with apt-get -y install ncat (to send messages to a socket)
  • Run ncat 172.17.0.1 12233 to connect, then type hello world and press enter
  • If it works, you should see the same string replied back

Possibility 3
What version of docker engine are you running on the box? Could we try an uninstall / re-install of the docker engine with a reboot of the box in between to rule that out? I've seen some versions of docker behaving oddly like this before... Note that you would lose any volumes/images/containers you had by doing this (but that should hopefully be ok?)

Possibility 2
I can't think of a test that doesn't involve making an alternate version of the extension where it only starts the IDE client listener (without doing the docker-compose subcommand) and then use something like ncat to prod it and see if it really is there.. I think we can go here if the two tests above are fruitless and at least things will be narrowed down more then.

@plotbox-io
Copy link
Owner

Perhaps this is an upstream issue? Maybe related to psalm/psalm-vscode-plugin#176 (comment)?

Not sure on that. Although the upstream has moved on a fair bit it seems from the fork that this fork is made from, you have to remember that the code is working perfectly fine for my team's docker dev configuration. So there must be a subtle environmental difference in the mix somewhere between yours and ours that we need to root out. It is a bit of a tricky one though..

@shaneparsons
Copy link
Author

shaneparsons commented Jun 24, 2022

Possibility 1 Firstly, the ability of the container to 'talk' to an open port on the box:

  • On the box: Install socat with sudo apt install socat
  • On the box: Run socat -v tcp-l:12233,fork exec:'/bin/cat' to start a simple 'echo server'
  • Bash inside your running docker container with something like docker-compose exec php bash (assuming php is the main service name)
  • Install ncat inside container with apt-get -y install ncat (to send messages to a socket)
  • Run ncat 172.17.0.1 12233 to connect, then type hello world and press enter
  • If it works, you should see the same string replied back

Hmm, so it looks like ncat is timing out from within the container

root@0da5d4c6cad4:/var/www/html# ncat 172.17.0.1 12233
Ncat: TIMEOUT.

P.S. I double checked the ping and it works

root@0da5d4c6cad4:/var/www/html# ping 172.17.0.1
PING 172.17.0.1 (172.17.0.1) 56(84) bytes of data.
64 bytes from 172.17.0.1: icmp_seq=1 ttl=64 time=0.082 ms
64 bytes from 172.17.0.1: icmp_seq=2 ttl=64 time=0.083 ms
64 bytes from 172.17.0.1: icmp_seq=3 ttl=64 time=0.208 ms

@plotbox-io
Copy link
Owner

plotbox-io commented Jun 24, 2022

Interesting. There is clearly something blocking your container's ability to talk via a port to it's host in general.

I saw this stack overflow just now and it made me think.. Could your container and the box both be sharing the same network (and thus sharing the same ports causing some sort of conflict). I.e., do you set the network_mode of "host" in docker-compose.yml? Or is there anything different about the networking configuration of your docker-compose.yml file(s)?

We are using the default 'bridge' mode and expose only a couple of ports to the host (the box in your case) such as port 80 and port 443

@shaneparsons
Copy link
Author

shaneparsons commented Jun 24, 2022

I don't see any references to network_mode or host in any of the compose files, but this container does share a network with a bunch of other containers in the box. The main nginx container w/ the proxy is shared here as well, and is separate from the nginx that's built into this php container.

Here's the docker inspect of the shared network (irrelevant containers removed):

[
    {
        "Name": "mono_default",
        "Id": "1c03ce82c25332061772cce91cd728117b38b0ad94dbe54e8d0f77a3bab83f86",
        "Created": "2022-06-22T20:36:09.40449613Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.20.0.0/16",
                    "Gateway": "172.20.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "0da5d4c6cad4f0369c2307dfa4c5f265800802cc442bcdc51fe60413722fa4a2": {
                "Name": "dme_dme-app_1",
                "EndpointID": "1262346f555a17ae60a74644b57b55005e43b6606a7a403580d9efef7a0b373a",
                "MacAddress": "02:42:ac:14:00:11",
                "IPv4Address": "172.20.0.17/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "default",
            "com.docker.compose.project": "mono",
            "com.docker.compose.version": "1.26.0"
        }
    }
]

Here's the output of docker network ls

NETWORK ID     NAME           DRIVER    SCOPE
c13b9539585d   bridge         bridge    local
630f57f97cc0   host           host      local
1c03ce82c253   mono_default   bridge    local

@shaneparsons
Copy link
Author

shaneparsons commented Jun 24, 2022

Going back to your other suggestion:
I'm currently using Docker version 20.10.7 which is a year old at this point and Docker Composer version 1.26.0 which is 2 years old at this point...

There are a lot of apps / containers running w/ what I imagine are outdated docker configs at this point, so I'm not sure about the feasibility of upgrading the versions... I can enquire if we end up determining that that's the likely issue here though.

@plotbox-io
Copy link
Owner

plotbox-io commented Jun 27, 2022

Hi Shane. I was thinking about this at the weekend and, as this is likely some sort of edge case relating to the docker networking, I think the most robust solution is to add support for bypassing the need for the container to communicate with the host directly and instead communicate via the general internet.

To achieve this, I've pushed a new version with support for using 'ngrok' as an alternative to the 'dockerHostDomainOrIp' setting. Now, when psalm_docker.ngrok is set to true, on start-up of the extension, ngrok is used initialise a dynamic domain and random port tunnel. The domain and port is then fed to the docker container psalm language server command so it will talk back to that.

It all seems to be running fine on my setup so was hoping you could give it a try and see if it solves things for you. Let me know!

Kind regards,
Richard

@shaneparsons
Copy link
Author

Hey man, great idea on ngrok!

Just gave it a few tries. The first complained about not being able to connect to host.docker.internal, which was weird since psalm_docker.dockerHostDomainOrIp is being ignored... So I tried again a couple more times, and now it just gets stuck in a Psalm: starting process, without much in terms of output:

Output
localUriPath: file:///home/sparsons/repo/dme

remoteUriPath: file:///var/www/html/src

psalm_docker.localDockerComposePaths: /home/sparsons/repo/dme/docker-compose.override.yml,/home/sparsons/repo/dme/docker-compose.yml

psalm_docker.remotePsalmServerPath: /var/www/html/vendor/bin/psalm-language-server

psalm_docker.localPath: /home/sparsons/repo/dme

psalm_docker.remotePath: /var/www/html/src

psalm_docker.remotePsalmXmlPath: /var/www/html/psalm.xml

psalm_docker.dockerServiceName: dme-app

Perhaps some new uncaught exception?

@plotbox-io
Copy link
Owner

plotbox-io commented Jun 27, 2022

The first complained about not being able to connect to host.docker.internal, which was weird since psalm_docker.dockerHostDomainOrIp is being ignored...

I think this must have still been an old version of the extension or else the ngrok setting was not getting picked up maybe. In any case, sounds like you got past that

now it just gets stuck in a Psalm: starting process, without much in terms of output

Hmm, must be the ngrok connect command failing. I'll see if I can maybe handle errors in that part a bit better. In meantime, could you check for errors using this technique please to see if any information is there that could be useful?

Thanks

@plotbox-io
Copy link
Owner

New version up. Essentially added a try/catch around the ngrok initialisation code. Hopefully if you try with this new version you might get some output as to why it is not working in your enviroment (the box).

Might be worth trying to run ngrok on your VM box manually using the traditional CLI tooling. Could you try using the ngrok cli to start a tcp connection on some random port (see [here](ngrok tcp 1234)) and see if it works or if there is some issue there. I think that can help us rule some things out.

Thanks for your ongoing efforts in working with me on this!

Regards,
Richard

@shaneparsons
Copy link
Author

shaneparsons commented Jun 27, 2022

Getting this output from the plugin now

Error initiating ngrok tunnel!
failed to start tunnel
There was an error initiating ngrok tunnel

I did install ngrok and was able to get it running in my box though:

Details
ngrok tcp 1234
ngrok                                                              (Ctrl+C to quit)

Hello World! https://ngrok.com/next-generation

Session Status                online
Account                       Shane Parsons (Plan: Free)
Version                       3.0.5
Region                        United States (us)
Latency                       12ms
Web Interface                 http://127.0.0.1:4043
Forwarding                    tcp://4.tcp.ngrok.io:12331 -> localhost:1234

Connections                   ttl     opn     rt1     rt5     p50     p90
                              0       0       0.00    0.00    0.00    0.00

I was also to get it running w/ the docker command:

Details
docker run -it -e NGROK_AUTHTOKEN=<token> ngrok/ngrok tcp 1234
ngrok                                                              (Ctrl+C to quit)

Hello World! https://ngrok.com/next-generation

Session Status                online
Account                       Shane Parsons (Plan: Free)
Update                        update available (version 3.0.5, Ctrl-U to update)
Version                       3.0.5
Region                        United States (us)
Latency                       -
Web Interface                 http://0.0.0.0:4040
Forwarding                    https://5661-184-72-212-10.ngrok.io -> http://localho

Connections                   ttl     opn     rt1     rt5     p50     p90
                              0       0       0.00    0.00    0.00    0.00

@plotbox-io
Copy link
Owner

Thanks for the information @shaneparsons. Hmm, that is a bit frustrating (but still progress!)

So we know that there is no issue per se with initialising ngrok on the box, just that when we try to do so via the extension / Javascript library, it has an error..

I've updated again. I realised I didn't output the stack trace or the error name to the debug output on failure, only the message. This other info might help lead us to the reason for the failure. Please could you try again and report if anything else useful shows in the output?

Finally, if you would like, and feel comfortable doing so, it might help if you could debug the extension directly. I realise this is a bit of an ask but it is proving hard for me to reproduce these issues myself. It is actually super simple to get set up to test the extension in a debugging mode:

  • Clone the repo
  • Run npm i from the root
  • Hit F5 on keyboard
  • In the new debugging visual studio window that appears, open the project folder you'd like to run Psalm on
  • Open a PHP file
  • Notice the extension will fire its initialisation logic (this only happens once on first load)

All the code is in src/extension.ts. Breakpoints should work off the bat. The bit we are having trouble with currently is around line 117 (you will see my try catch attempts at getting more info here):

ngrokUrlResult = await ngrok.connect({ proto: 'tcp', addr: address.port });

We might be able to learn something by using breakpoints to dig into the ngrok library a little and see what the core problem is. The connect function lives here: node_modules/ngrok/index.js (also possible to add breakpoints and step into here)

@shaneparsons
Copy link
Author

Sounds good! I'll try to find some time to debug further later today.

@shaneparsons
Copy link
Author

Not too much more useful unfortunately...

failed to start tunnel (NgrokClientError)
NgrokClientError: failed to start tunnel
	at NgrokClient.request (/home/sparsons/.vscode-server/extensions/plotbox.better-psalm-docker-vscode-1.0.10/node_modules/ngrok/src/client.js:33:23)
	at runMicrotasks (<anonymous>)
	at processTicksAndRejections (node:internal/process/task_queues:96:5)
	at async connectRetry (/home/sparsons/.vscode-server/extensions/plotbox.better-psalm-docker-vscode-1.0.10/node_modules/ngrok/index.js:29:22)
	at async Server.<anonymous> (/home/sparsons/.vscode-server/extensions/plotbox.better-psalm-docker-vscode-1.0.10/out/extension.js:94:38)
There was an error (NgrokClientError) initiating ngrok tunnel to random server port 35101
Error initiating ngrok tunnel!

I'm gonna try debugging on my end as you suggested and will let you know if I make any progress.

@shaneparsons
Copy link
Author

I'm having trouble getting any of the breakpoints to work... I'm wondering if it's because I have the plugin cloned locally, and I'm trying to test from within my box? Should I have cloned the plugin to the box instead?

@plotbox-io
Copy link
Owner

Ah, I think I know why it was failing. I was testing again using remote ssh into my Ubuntu VM and got this:
image

Looks like I just happened to already have signed up for an ngrok account on my local so I never got this message.. Now that I see the exact sub-type for the error, I can better handle the exception to provide debug output going forward.

I'll test now and see what the best process for signing up is.. Might be possible to add an extra config param for ngrok user credentials and some blurb in readme.

@plotbox-io
Copy link
Owner

plotbox-io commented Jun 28, 2022

Hi Shane. I've puished a new update that adds psalm_docker.ngrokAuthToken setting along with notes in the readme. I've tested in ssh remote mode both with (valid token) and without/invalid (i.e., showing relevant debug errors) and all looks working as expected for me. Could you try the new version and let me know how it goes?

@shaneparsons
Copy link
Author

shaneparsons commented Jun 28, 2022

Woo, it's alive!!

There were a few attempts in (in between first success and current success) where I was getting Error: Invalid ngrok token!" errors for some reason, even though the token didn't change, but it seems to be working now. If it happens again I'll open another issue and we can investigate further.

Thanks for all the time you spent working on this with me man! It's definitely going to be part of my every day workflow.

@plotbox-io
Copy link
Owner

Fantastic news!

Yeah, for my first OSS issue, this one was a doozie alright haha

Glad it is working for you now Shane :)

Best,
Richard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants