Skip to content

gh cs port forward does not close http connection #6842

@binotaliu

Description

@binotaliu

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.

Screen recording of running a command "curl localhost:8888", which returns the output of phpinfo(), and the command stays running
When using curl, it keeps running.

A chromium browser window viewing at url localhost:8888, displaying the output of "phpinfo()". The spinner in front of the page title is spinning, indicates that the page is still loading. A debug window is opened, with the tab "network" shows a yellow warning text says "CAUTION: request is not finished yet!"
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:
CleanShot 2023-01-12 at 00 00 49

Output on my local machine by running curl localhost:8888, where 8888 is forwarded by gh command:
CleanShot 2023-01-12 at 00 01 17

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

  1. Create a new repository on GitHub. Then creates a file inside it to initialise a branch.
  2. Create a new GitHub Codespace using the repository created in step 1.
  3. Waiting for the Codespace to be created.
  4. Open Terminal app on your local machine.
  5. Run command gh cs ssh in the terminal window you just opened, then select the Codespace created in step 1.
  6. Run command echo "<?php phpinfo();" > info.php inside the SSH connection to create a php file for test.
  7. Run command php -S 0.0.0.0:8888 info.php to start PHP's build-in web server. Keep this terminal window opening.
  8. Open a new terminal window on your local machine.
  9. Run command gh cs port forward 8888:8888 on the terminal window you opened in step 8. Keep this terminal window opening.
  10. Open a new terminal window on your local machine.
  11. Run command curl localhost:8888. The curl command will keep running until you hit Ctrl-C to 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

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