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

Add timeout named argument to 'Socket.connect', etc. #19120

Closed
DartBot opened this issue May 31, 2014 · 12 comments
Closed

Add timeout named argument to 'Socket.connect', etc. #19120

DartBot opened this issue May 31, 2014 · 12 comments
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented May 31, 2014

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?

  • expected: 5 seconds, TimeoutException, exit
  • instead: 5 seconds, TimeoutException, 2 minutes, exit

What version of the product are you using? On what operating system?

  • 64 bit linux (Ubuntu)
@sethladd
Copy link
Contributor

sethladd commented Jun 2, 2014

Added Library-IO, Area-Library, Triaged labels.

@andersjohnsen
Copy link

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.
Added Type-Enhancement label.
Changed the title to: "Add timeout named argument to 'Socket.connect', etc.".

@DartBot
Copy link
Author

DartBot commented Jun 10, 2014

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...)

@DartBot
Copy link
Author

DartBot commented Nov 19, 2014

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.

@DartBot DartBot added Type-Enhancement library-io area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Nov 19, 2014
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed priority-unassigned labels Feb 29, 2016
@floitschG
Copy link
Contributor

floitschG commented May 29, 2017

@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 timeout, but that feels expensive. It would provide one of the nicest APIs' though.

Alternatively, we could add named timeout arguments to the relevant functions.

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.

@sircco
Copy link

sircco commented May 31, 2017

@floitschG

it would be nice if timeout could be differentiated by send/recv timeout via setsockopt or similar method

here is what python does
some high level functions expose socket via instance._get_socket()
then you use socket.settimeout(n) for that socket

also relevant functions have timeout param. i.e.
https://docs.python.org/3/library/http.client.html
https://docs.python.org/2/library/smtplib.html

similar stuff is in golang, with Conn interface with dial timeout and deadlines
https://golang.org/pkg/net/

as i see from docs dart's setsockopt is very limiting

@zanderso
Copy link
Member

zanderso commented Jun 6, 2017

Taking a brief look, I think the approach we should consider is wiring up sendTimeout and recvTimeout named arguments to connect (on Socket) and bind (on ServerSocket for sockets we get back from accept) to setsockopt with SO_RCVTIMEO and SO_SNDTIMEO.

If there's demand for it going forward, we can consider providing a more general API for accessing socket options.

@bkonyi
Copy link
Contributor

bkonyi commented Jun 7, 2017

Would it maybe just make more sense to add a SocketOptions class and have connect and bind consume that? That way we won't have to change the interface for Socket and ServerSocket if we do eventually decide to allow for additional configuration options.

@zanderso
Copy link
Member

zanderso commented Jun 8, 2017

@bkonyi sgtm.

@floitschG Thoughts about @bkonyi's suggestion?

@floitschG
Copy link
Contributor

Normally, named arguments scale quite nicely. What would be the advantage of having a SocketOptions class?

@bkonyi bkonyi closed this as completed in 86fdbde Jun 21, 2017
@allComputableThings
Copy link

allComputableThings commented Jan 8, 2020

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).

@bkonyi
Copy link
Contributor

bkonyi commented Jan 8, 2020

At this point, I don't think so. It's probably worth filing a feature request for though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

9 participants