Skip to content

Commit 24936fe

Browse files
jakemac53Commit Queue
authored and
Commit Queue
committed
[macros] ensure we close the socket if the process fails to start
Change-Id: I29a9583080d27ce286d0c2f9f7dfa2d267b60b9d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332600 Commit-Queue: Konstantin Shcheglov <[email protected]> Commit-Queue: Jake Macdonald <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Auto-Submit: Jake Macdonald <[email protected]>
1 parent f644a30 commit 24936fe

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pkg/_fe_analyzer_shared/lib/src/macros/executor/process_executor.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,17 @@ class _SingleProcessMacroExecutor extends ExternalMacroExecutorBase {
6060
} on SocketException catch (_) {
6161
serverSocket = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
6262
}
63-
Process process = await Process.start(programPath, [
64-
...arguments,
65-
serverSocket.address.address,
66-
serverSocket.port.toString(),
67-
]);
63+
Process process;
64+
try {
65+
process = await Process.start(programPath, [
66+
...arguments,
67+
serverSocket.address.address,
68+
serverSocket.port.toString(),
69+
]);
70+
} catch (e) {
71+
await serverSocket.close();
72+
rethrow;
73+
}
6874
process.stderr
6975
.transform(const Utf8Decoder())
7076
.listen((content) => throw new RemoteException(content));

0 commit comments

Comments
 (0)