Skip to content

Commit

Permalink
Close Ipv4 server when failing to start Ipv6 (flutter#12)
Browse files Browse the repository at this point in the history
Fixes a bug that could prevent the VM from shutting down if there is a
port conflict with Ipv6 but not Ipv4.
  • Loading branch information
natebosch authored Apr 25, 2019
1 parent ca11562 commit 63aecc8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.6

* If there is a problem starting a loopback Ipv6 server, don't keep the Ipv4
server open when throwing the exception.

## 2.0.5

* Update SDK constraints to `>=2.0.0-dev <3.0.0`.
Expand Down
5 changes: 4 additions & 1 deletion lib/http_multi_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,17 @@ class HttpMultiServer extends StreamView<HttpRequest> implements HttpServer {
var v6Server = await bind(InternetAddress.loopbackIPv6, v4Server.port);
return HttpMultiServer([v4Server, v6Server]);
} on SocketException catch (error) {
// If there is already a server listening we'll lose the reference on a
// rethrow.
await v4Server.close();

if (error.osError.errorCode != _addressInUseErrno) rethrow;
if (port != 0) rethrow;
if (remainingRetries == 0) rethrow;

// A port being available on IPv4 doesn't necessarily mean that the same
// port is available on IPv6. If it's not (which is rare in practice),
// we try again until we find one that's available on both.
await v4Server.close();
return await _loopback(port, bind, remainingRetries - 1);
}
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: http_multi_server
version: 2.0.6-dev
version: 2.0.6

description: A dart:io HttpServer wrapper that handles requests from multiple servers.
author: Dart Team <misc@dartlang.org>
Expand Down

0 comments on commit 63aecc8

Please sign in to comment.