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

custom dialer in fasthttp.Client does not respect request timeout #1664

Closed
avivpxi opened this issue Nov 17, 2023 · 3 comments
Closed

custom dialer in fasthttp.Client does not respect request timeout #1664

avivpxi opened this issue Nov 17, 2023 · 3 comments

Comments

@avivpxi
Copy link
Contributor

avivpxi commented Nov 17, 2023

If a custom dialer is set when using a fasthttp.Client, request timeout will not be respected if a dial operation hangs.

example code:

customDialer := fasthttp.TCPDialer{
	DNSCacheDuration: time.Hour,
}
client := &fasthttp.Client{
	Dial: customDialer.Dial,
}
req := fasthttp.AcquireRequest()
resp := fasthttp.AcquireResponse()
client.DoTimeout(req, resp, time.Millisecond * 500)

with this code, if customDialer.Dial call hangs, you would expect client.DoTimeout to still fail after 500ms, but it would actually occur after 3s due to the default dialer timeout. Note how this function call actually ignores dialTimeout which is respected if no custom dialer was set.

I know we can't control any external dialer implementation if it chooses to ignore timeouts, but I think we should document here that overriding the default dialer causes request timeouts to be ignored.

Furthermore, I think we can consider adding a secondary [DialFunc](https://github.com/valyala/fasthttp/blob/master/client.go#L625) type that accepts timeout to allow custom dialers to respect request timeouts. Note that currently, if I use the built-in dialer with a custom setting (like the example above) I can't set a per-request timeout. Only a global one - meaning when I create a custom dialer I can set it's timeout using the global timeout variable, but if I want to dispatch different requests with different timeouts, the current dialer interface can't support it.

If it matters, i'd be happy to contribute to either the doc change or the implementation change if either is considered.

@erikdubbelboer
Copy link
Collaborator

I agree. A pull request for the documentation and DialFuncWithTimeout would also be very welcome! I don't have time to build this myself.

@avivpxi
Copy link
Contributor Author

avivpxi commented Nov 25, 2023

on it.

@avivcarmis
Copy link
Contributor

PR - #1669

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