Skip to content

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

@ItalyPaleAle

Description

@ItalyPaleAle
  • 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.

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable bugplan-reviewPM-highlighted item determined to be P1 or P2remote-explorer

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions