-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add timeout named argument to 'Socket.connect', etc. #19120
Comments
Added Library-IO, Area-Library, Triaged labels. |
Calling 'timeout' on a future does not stop the original operation that completes the future. A timeout of 2 minute is default on most systems. The real way to 'fix' this would be to add a named argument 'timeout' to Socket.connect & others, that would override the default 2 minute timeout. Removed Type-Defect label. |
This comment was originally written by ef...@gmail.com Sure it would help, but would it be better to cancel socket operations by client.close() or some equivalent? Closing socket/client with command is actualy more controllable in "dart way" then "static" timeout (and without changing api for now). (But setting socket timeout should added in future ofcourse...) |
This comment was originally written by greg.lo...@gmail.com This would be great to have for use in the postgresql library. These 2 min hangs are a real pain when running unittests. But more importantly I'd like to be able to set a lower timeout in the connection pool. |
@zanderso : this just came up on gitter. What's your opinion? We could wrap all futures that are returned by socket operations and back-propagate the Alternatively, we could add named Another approach would be to set the timeout time globally. That would make unit-testing easier/faster. Finally, we could have a method that actively cancels any running operation. |
it would be nice if timeout could be differentiated by send/recv timeout via setsockopt or similar method here is what python does also relevant functions have timeout param. i.e. similar stuff is in golang, with Conn interface with dial timeout and deadlines as i see from docs dart's setsockopt is very limiting |
Taking a brief look, I think the approach we should consider is wiring up If there's demand for it going forward, we can consider providing a more general API for accessing socket options. |
Would it maybe just make more sense to add a SocketOptions class and have |
@bkonyi sgtm. @floitschG Thoughts about @bkonyi's suggestion? |
Normally, named arguments scale quite nicely. What would be the advantage of having a |
Is there any plan to add a "socket timeout" (a timeout associated with send/recv), instead of just the connect timeout? (AFAIK 86fdbde only added add the connect timeout). |
At this point, I don't think so. It's probably worth filing a feature request for though. |
This issue was originally filed by ef...@gmail.com
What steps will reproduce the problem?
import 'dart:io';
main() {
var client = new HttpClient();
client.getUrl(Uri.parse('http://8.8.8.9')) // host without response
.timeout(const Duration(seconds: 5))
.then((HttpClientRequest request) {
print("hell no.");
})
.catchError((e) => print(e.toString()))
.whenComplete(() => client.close(force: true));
}
What is the expected output? What do you see instead?
What version of the product are you using? On what operating system?
The text was updated successfully, but these errors were encountered: