-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
Describe the bug
gh version 2.21.2 (2023-01-03)
I noticed a very weird behaviour when using the command gh cs port forward 80:8888 to forward PHP's Build-in Web Server, the connection will not be closed.

When using curl, it keeps running.

The spinner on the page title of chromium browser keep spinning. "Network" developer tools show a warning says that the request is not finished.
What's even weird is that the response body is missing the last line.
This is what the output should look like, which is the output of the command curl localhost:8888 inside the Codespaces instance:

Output on my local machine by running curl localhost:8888, where 8888 is forwarded by gh command:

It only happens when forwarding ports using gh cs port forward, but not when using JetBrains IDE's port forwarding feature, nor when using *.preview.app.github.dev URL to access the port.
Steps to reproduce the behavior
- Create a new repository on GitHub. Then creates a file inside it to initialise a branch.
- Create a new GitHub Codespace using the repository created in step 1.
- Waiting for the Codespace to be created.
- Open Terminal app on your local machine.
- Run command
gh cs sshin the terminal window you just opened, then select the Codespace created in step 1. - Run command
echo "<?php phpinfo();" > info.phpinside the SSH connection to create a php file for test. - Run command
php -S 0.0.0.0:8888 info.phpto start PHP's build-in web server. Keep this terminal window opening. - Open a new terminal window on your local machine.
- Run command
gh cs port forward 8888:8888on the terminal window you opened in step 8. Keep this terminal window opening. - Open a new terminal window on your local machine.
- Run command
curl localhost:8888. The curl command will keep running until you hitCtrl-Cto terminate it.
Expected vs actual behavior
Expected Behaviour: The command curl localhost:8888 should stop after the http response received.
Actual Behaviour: The command curl localhost:8888 does not stop even though the
Logs
Described in the steps to reproduce.
Update for anyone who are facing the same issue: You can use ssh tunnel as an alternative:
gh cs ssh -- -L 8703:localhost:80
will forward remote's localhost:80 to the 8703 port on your local machine. If you need more than one port, just append more -L options:
gh cs ssh -- -L 8703:localhost:80 -L 5173:localhost:5173