Skip to content

Commit 779dc6e

Browse files
Adam Barthcommit-bot@chromium.org
authored andcommitted
Stop leaking file descriptors for HTTP clients
Previously, we would wait for a Future to terminate before destroying the underlying raw socket. If that future never terminated, we would leak the underlying file descriptor. Now, the "force" codepath in close destroys the socket immediately (similar to what it did previously for active sockets) and the non-force codepath has a timeout, as requested by a TODO comment. Change-Id: I021a93a40e4708ce93b4f1ae6c3f7289764bd69f Reviewed-on: https://dart-review.googlesource.com/54442 Reviewed-by: Zach Anderson <[email protected]> Commit-Queue: Adam Barth <[email protected]>
1 parent b294e48 commit 779dc6e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

sdk/lib/_http/http_impl.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,8 +1766,7 @@ class _HttpClientConnection {
17661766
void close() {
17671767
closed = true;
17681768
_httpClient._connectionClosed(this);
1769-
_streamFuture
1770-
// TODO(ajohnsen): Add timeout.
1769+
_streamFuture.timeout(_httpClient.idleTimeout)
17711770
.then((_) => _socket.destroy());
17721771
}
17731772

@@ -1885,13 +1884,17 @@ class _ConnectionTarget {
18851884
}
18861885

18871886
void close(bool force) {
1888-
for (var c in _idle.toList()) {
1889-
c.close();
1890-
}
18911887
if (force) {
1888+
for (var c in _idle.toList()) {
1889+
c.destroy();
1890+
}
18921891
for (var c in _active.toList()) {
18931892
c.destroy();
18941893
}
1894+
} else {
1895+
for (var c in _idle.toList()) {
1896+
c.close();
1897+
}
18951898
}
18961899
}
18971900

0 commit comments

Comments
 (0)