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

Allow the user to set a custom timeout for dialing a host #92

Closed
wants to merge 1 commit into from
Closed

Allow the user to set a custom timeout for dialing a host #92

wants to merge 1 commit into from

Conversation

jkawamoto
Copy link
Contributor

In addition to #90, it would be helpful if the user can set the timeout for dialing a host to a custom value.

@lukechampine
Copy link
Owner

#90 was pretty simple, but I'm less sure how this should be handled.

Technically there are two timeouts here: one for dialing the host, and another for performing the initial handshake. Sometimes you want to use a single timeout that covers both operations, and other times you want to use distinct timeouts. So the API could get pretty ugly.

Perhaps the best approach would be to add a NewSessionFromConn function that takes a conn already initialized by the caller. You would use it like so:

conn, err := net.DialTimeout("tcp", string(hostIP), customDialTimeout)
if err != nil {
	return nil, err
}
conn.SetDeadline(time.Now().Add(customHandshakeTimeout))
s, err := proto.NewSessionFromConn(conn, hostKey, currentHeight)
if err != nil {
	return nil, err
}

This would also allow the use of e.g. DialContext if you want to use contexts to manage cancellation. And since Conn is an interface, you could wrap it if desired, much like how statsConn works. (Hmm, maybe statsConn could be moved out of proto entirely...)

@jkawamoto
Copy link
Contributor Author

Context-based cancellation sounds good. It'd be handly If PseudoKV #67 supports it. On the other hand, I think it's not good for PseudoFS because adding ctx to each method makes PseudoFS less compatible with the typical FileSystem interface.

@jkawamoto jkawamoto deleted the dial_timeout branch October 24, 2020 02:45
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

Successfully merging this pull request may close these issues.

2 participants