[dart-announce] Calling close on dart:io HttpClient is now required

115 views
Skip to first unread message

Søren Gjesse

unread,
Aug 26, 2014, 6:31:00 AM8/26/14
to anno...@dartlang.org

In r39542 we changed the dart:io HttpClient shutdown handling. This

enables proper handling of HTTP persistent connections. However this also

adds the requirement for calling HttpClient.close when done using it. Failing

to call HttpClient.close can cause your dart:io programs to hang until the

HttpClient.idleTimeout has expired after all I/O activity has otherwise

completed. The default value for HttpClient.idleTimeout is 15 seconds.


Note that the documentation for dart:io HttpClient have always stated that

calling HttpClient.close was required to close idle persistent connections.


If you are experiencing shutdown issues with your dart:io program which might

be related to this change, you can simulate the behavior from before this

change by lowering client.idleTimeout:


 var client = new HttpClient();

 client.idleTimeout = const Duration(milliseconds: 100);


This should only be used as a short term workaround. Tracking your HttpClient

instances and closing them properly is the right thing to do.


This change will be part of the first 1.7 developer release.


--
For more news and information, visit http://news.dartlang.org/
 
To join the conversation, visit https://groups.google.com/a/dartlang.org/

tomaszkubacki

unread,
Aug 26, 2014, 6:59:01 AM8/26/14
to mi...@dartlang.org, anno...@dartlang.org, e...@dartlang.org
seeing that, I miss from C#
using statement.

e.g

using(some_disposable_resource){
...//do some operations on some_disposable_resource
}

//will be disposed,closed,whatever here....

Martin Kustermann

unread,
Aug 26, 2014, 8:13:34 AM8/26/14
to mi...@dartlang.org, anno...@dartlang.org, e...@dartlang.org
You can potentially implement this yourself. The new await/async syntax will make it significantly easier to implement. The only requirement is that you get a Future which completes once you're done with an HttpClient. For example:

Something like this:

// Usage:
var client = new HttpClient();
using(client, () {
  return await someOperation(client);
});

// Implementation of using
Future using(resource, operation) {
  return operation().whenComplete(() => resource.close());
}




--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

'Bob Nystrom' via Dart Announcements

unread,
Aug 26, 2014, 12:47:27 PM8/26/14
to e...@dartlang.org, General Dart Discussion, announce
On Tue, Aug 26, 2014 at 5:13 AM, 'Martin Kustermann' via Dart Announcements <anno...@dartlang.org> wrote:
You can potentially implement this yourself. The new await/async syntax will make it significantly easier to implement. The only requirement is that you get a Future which completes once you're done with an HttpClient. For example:

Something like this:

// Usage:
var client = new HttpClient();
using(client, () {
  return await someOperation(client);
});

To use await here, you also have to mark the function async:

using(client, () async {
  return await someOperation(client);
});

But it isn't buying you anything in this case. You can just do:

using(client, () {
  return someOperation(client);
});

or even:

using(client, () => someOperation(client));

- bob

--
For more news and information, visit https://plus.google.com/+dartlang

Cogman

unread,
Aug 26, 2014, 1:57:01 PM8/26/14
to mi...@dartlang.org
Yeah. It would be nice if dart had a resource leak prevention thingy (try with resources in java, using C#, destructors in C++).


--
Reply all
Reply to author
Forward
0 new messages