Skip to content

Commit 63aecc8

Browse files
authored
Close Ipv4 server when failing to start Ipv6 (flutter#12)
Fixes a bug that could prevent the VM from shutting down if there is a port conflict with Ipv6 but not Ipv4.
1 parent ca11562 commit 63aecc8

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.0.6
2+
3+
* If there is a problem starting a loopback Ipv6 server, don't keep the Ipv4
4+
server open when throwing the exception.
5+
16
## 2.0.5
27

38
* Update SDK constraints to `>=2.0.0-dev <3.0.0`.

lib/http_multi_server.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,17 @@ class HttpMultiServer extends StreamView<HttpRequest> implements HttpServer {
145145
var v6Server = await bind(InternetAddress.loopbackIPv6, v4Server.port);
146146
return HttpMultiServer([v4Server, v6Server]);
147147
} on SocketException catch (error) {
148+
// If there is already a server listening we'll lose the reference on a
149+
// rethrow.
150+
await v4Server.close();
151+
148152
if (error.osError.errorCode != _addressInUseErrno) rethrow;
149153
if (port != 0) rethrow;
150154
if (remainingRetries == 0) rethrow;
151155

152156
// A port being available on IPv4 doesn't necessarily mean that the same
153157
// port is available on IPv6. If it's not (which is rare in practice),
154158
// we try again until we find one that's available on both.
155-
await v4Server.close();
156159
return await _loopback(port, bind, remainingRetries - 1);
157160
}
158161
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: http_multi_server
2-
version: 2.0.6-dev
2+
version: 2.0.6
33

44
description: A dart:io HttpServer wrapper that handles requests from multiple servers.
55
author: Dart Team <[email protected]>

0 commit comments

Comments
 (0)