microsoft / microsoft/vscode-remote-release

SSH & port forwarding: connections aren't closed in the server

Open
#3,561 18 comments 7 reactions 1 assignee View on GitHub

@alexr00 is already working on this.

Since Sep 24, 2020.

bug plan-review remote-explorer
Dominant language
Dockerfile
Stars
4.2k
Forks
470
Avg merge
1d 1h
Merged PRs (30d)
1

Description

  • VSCode Version: 1.48.1
  • Local OS Version: macOS 10.15.6
  • Remote OS Version: Debian 10
  • Remote Extension/Connection Type: SSH

This is a tricky one. Inside a remote-SSH, run the following Go code:

package main

import (
	"bytes"
	"fmt"
	"net/http"
)

func main() {
	http.HandleFunc("/test", func(w http.ResponseWriter, req *http.Request) {
		fmt.Println("Request starting")
		p := bytes.Repeat([]byte("x"), 1000)
		for i := 0; i < 100000; i++ {
			// Goroutine hangs here
			_, err := w.Write(p)
			if err != nil {
				fmt.Println("error:", err)
				return
			}
		}
		fmt.Println("Request done")
	})
	http.ListenAndServe("127.0.0.1:8090", nil)
}

Launch it using the terminal with:

go run .

Then forward port 8090 to the client.

  1. In another terminal inside the remote server (recommend using an external terminal, as using the integrated terminal might make VS Code hang), run: curl http://localhost:8090/test then abort the request (CTRL+C). In the terminal that is running the app, you'll see an error: error: write tcp 127.0.0.1:8090->127.0.0.1:55264: write: connection reset by peer
  2. In the local machine, run the same command: curl http://localhost:8090/test then like before abort the request (CTRL+C) before it's done. You'll see that nothing happens in the app that is running, no error message (it only shows Request starting).

This seems to be caused by the fact that the tunnel does not transmit the closing of the connection. In fact, if you add fmt.Println(i) before _, err := w.Write(p), you see that the app keeps transmitting data even after curl is stopped. That data probably goes into some stream in the system or in VS Code, and creates backpressure. At a certain point, because there's nothing consuming that stream, the stream is full and the app hangs, unable to add more data.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.