easyssh-proxy icon indicating copy to clipboard operation
easyssh-proxy copied to clipboard

Timeout argument ignored when using proxy

Open ascheel opened this issue 1 year ago • 3 comments

Timeouts are adhered to when connecting directly to a server. Once a proxy is introduced, the timeout seems to be ignored.

package main

import (
	"fmt"
	"os"
	"time"

	"github.com/appleboy/easyssh-proxy"
	"path/filepath"
)

func main() {
	homedir, err := os.UserHomeDir()
	if err != nil {
		fmt.Printf("Error: %v\n", err)
	}
	keypath := filepath.Join(homedir, ".ssh", "id_rsa")
	var easySSH *easyssh.MakeConfig
	easySSH = &easyssh.MakeConfig{
		User: "ec2-user",
		Server: "1.2.3.4",
		Port: "22",
		KeyPath: keypath,
		Timeout: 10 * time.Second,
		Proxy: easyssh.DefaultConfig{
			User: "ec2-user",
			Server: "5.6.7.8",
			Port: "22",
			KeyPath: keypath,
			Timeout: 10 * time.Second,
		},
	}

	fmt.Printf("Connecting...\n")
	timeStart := time.Now()
	stdout, stderr, isTimeout, err := easySSH.Run("ls -la", 10 * time.Second)
	timeEnd := time.Now()
	fmt.Printf("stdout: %v\n", stdout)
	fmt.Printf("stderr: %v\n", stderr)
	fmt.Printf("isTimeout: %v\n", isTimeout)
	fmt.Printf("err: %v\n", err)
	fmt.Printf("Duration: %v\n", timeEnd.Sub(timeStart))
}

(Please note the that the hostnames, usernames, and key names have been changed as they contain identifying information.)

Output:

[devops@maintenance3 proxytest]$ go build . && ./proxytest
stdout:
stderr:
isTimeout: false
err: ssh: rejected: connect failed (Connection timed out)
Duration: 2m10.101925449s

I have verified connectivity to the proxy host.

Version information: github.com/appleboy/easyssh-proxy v1.5.0

ascheel avatar Aug 23 '24 17:08 ascheel

Also I just noticed that the connection is not seen as a timeout (isTimeout: false)

ascheel avatar Aug 23 '24 18:08 ascheel

Experiencing this too 👀

scottenock avatar Dec 05 '24 13:12 scottenock

I think my issue was unrelated to yours, but I'm just adding some info for others if they're having trouble like me. I was being dense and didn't realise the proxy connection has independent config that doesn't inherit the config from the jump host.

I added some notes to the readme that you can see here

scottenock avatar Dec 17 '24 13:12 scottenock