From cbaf70ce99b2dc5689e545dac94d8a776e310cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Wed, 7 Feb 2018 08:54:21 -0800 Subject: [PATCH] Ensures that the Metro server is closed when an exception happens in runBuild Differential Revision: D6924180 fbshipit-source-id: 80f5bf60aa357ce8df0598e8fdac92776c4af601 --- packages/metro/src/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/metro/src/index.js b/packages/metro/src/index.js index 037631fd..4d4a6db1 100644 --- a/packages/metro/src/index.js +++ b/packages/metro/src/index.js @@ -320,7 +320,13 @@ exports.runBuild = async (options: RunBuildOptions) => { options.onBegin(); } - const metroBundle = await output.build(metroServer, requestOptions); + let metroBundle; + + try { + metroBundle = await output.build(metroServer, requestOptions); + } finally { + await metroServer.end(); + } if (options.onComplete) { options.onComplete(); @@ -337,7 +343,6 @@ exports.runBuild = async (options: RunBuildOptions) => { }; await output.save(metroBundle, outputOptions, console.log); - await metroServer.end(); return {metroServer, metroBundle}; };