Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout is fake? #60

Open
Cookiery opened this issue May 5, 2023 · 4 comments
Open

Timeout is fake? #60

Cookiery opened this issue May 5, 2023 · 4 comments

Comments

@Cookiery
Copy link

Cookiery commented May 5, 2023

image

Even if I add use the context.WithTimeout, but it does not effective
image

@dbarrosop
Copy link
Contributor

It is not fake but is left to be considered by the underlying task (SSHOpen) in your example, which seems to not be honoring it. Feel free to submit a PR fixing the issue.

@Cookiery
Copy link
Author

Cookiery commented May 5, 2023

OK, I will consider how to solve this problem and submit a PR fixing the issue.

@Cookiery
Copy link
Author

Cookiery commented May 5, 2023

Thanks for your reply!

@nleiva
Copy link
Collaborator

nleiva commented May 5, 2023

Looks like ssh.Dial doesn't take a context, which is what this package use:

https://github.com/nornir-automation/gornir/blob/master/pkg/plugins/connection/ssh.go#L72-L77

	client, err := ssh.Dial("tcp", fmt.Sprintf("%s:%d", host.Hostname, port), config)
	if err != nil {
		return &SSH{}, errors.Wrap(err, "failed to dial")
	}
	host.SetConnection("ssh", &SSH{client})
	return &SSH{client}, nil

Maybe a solution is what they describe here: golang/go#20288 (comment). In a nutshell, create a new Dial function in this package with a context which you can use instead.

func Dial(ctx context.Context, network, addr string, config *ssh.ClientConfig) (*ssh.Client, error) {
	d := net.Dialer{Timeout: config.Timeout}
	conn, err := d.DialContext(ctx, network, addr)
	if err != nil {
		return nil, err
	}
	c, chans, reqs, err := ssh.NewClientConn(conn, addr, config)
	if err != nil {
		return nil, err
	}
	return ssh.NewClient(c, chans, reqs), nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants