From d3a40be4791fb87884fff71f63a3cda077535ba8 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Mon, 3 Aug 2020 20:15:25 -0700 Subject: [PATCH] browser(firefox): reliably close the pipe (#3280) --- browser_patches/firefox/BUILD_NUMBER | 4 ++-- browser_patches/firefox/juggler/components/juggler.js | 6 +++++- .../firefox/juggler/pipe/nsRemoteDebuggingPipe.cpp | 4 +++- browser_patches/firefox/juggler/protocol/BrowserHandler.js | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/browser_patches/firefox/BUILD_NUMBER b/browser_patches/firefox/BUILD_NUMBER index e8a5d7b3fdf76..af93fbf506507 100644 --- a/browser_patches/firefox/BUILD_NUMBER +++ b/browser_patches/firefox/BUILD_NUMBER @@ -1,2 +1,2 @@ -1149 -Changed: dgozman@gmail.com Mon Aug 3 15:21:45 PDT 2020 +1150 +Changed: dgozman@gmail.com Mon Aug 3 19:37:50 PDT 2020 diff --git a/browser_patches/firefox/juggler/components/juggler.js b/browser_patches/firefox/juggler/components/juggler.js index d8f873702277c..e217e6796b3ff 100644 --- a/browser_patches/firefox/juggler/components/juggler.js +++ b/browser_patches/firefox/juggler/components/juggler.js @@ -94,7 +94,11 @@ CommandLineHandler.prototype = { const browserHandler = new BrowserHandler(dispatcher.rootSession(), dispatcher, targetRegistry, () => { if (silent) Services.startup.exitLastWindowClosingSurvivalArea(); - pipe.stop(); + // Send response to the Browser.close, and then stop in the next microtask. + Promise.resolve().then(() => { + connection.onclose(); + pipe.stop(); + }); }); dispatcher.rootSession().registerHandler('Browser', browserHandler); loadFrameScript(); diff --git a/browser_patches/firefox/juggler/pipe/nsRemoteDebuggingPipe.cpp b/browser_patches/firefox/juggler/pipe/nsRemoteDebuggingPipe.cpp index 5780ebd384cbd..229b0a64d4455 100644 --- a/browser_patches/firefox/juggler/pipe/nsRemoteDebuggingPipe.cpp +++ b/browser_patches/firefox/juggler/pipe/nsRemoteDebuggingPipe.cpp @@ -128,12 +128,14 @@ nsresult nsRemoteDebuggingPipe::Stop() { #if defined(_WIN32) CancelIoEx(readHandle, nullptr); CloseHandle(readHandle); + CloseHandle(writeHandle); #else shutdown(readFD, SHUT_RDWR); + shutdown(writeFD, SHUT_RDWR); #endif mReaderThread->Shutdown(); mReaderThread = nullptr; - mWriterThread->AsyncShutdown(); + mWriterThread->Shutdown(); mWriterThread = nullptr; return NS_OK; } diff --git a/browser_patches/firefox/juggler/protocol/BrowserHandler.js b/browser_patches/firefox/juggler/protocol/BrowserHandler.js index 5e55801ff2c3a..a9a06f2a41f26 100644 --- a/browser_patches/firefox/juggler/protocol/BrowserHandler.js +++ b/browser_patches/firefox/juggler/protocol/BrowserHandler.js @@ -125,13 +125,13 @@ class BrowserHandler { } async close() { - this._onclose(); let browserWindow = Services.wm.getMostRecentWindow( "navigator:browser" ); if (browserWindow && browserWindow.gBrowserInit) { await browserWindow.gBrowserInit.idleTasksFinishedPromise; } + this._onclose(); Services.startup.quit(Ci.nsIAppStartup.eForceQuit); }