browser(firefox): reliably close the pipe (#3280)

This commit is contained in:
Dmitry Gozman 2020-08-03 20:15:25 -07:00 committed by GitHub
parent 573f580fa8
commit d3a40be479
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 5 deletions

View file

@ -1,2 +1,2 @@
1149 1150
Changed: dgozman@gmail.com Mon Aug 3 15:21:45 PDT 2020 Changed: dgozman@gmail.com Mon Aug 3 19:37:50 PDT 2020

View file

@ -94,7 +94,11 @@ CommandLineHandler.prototype = {
const browserHandler = new BrowserHandler(dispatcher.rootSession(), dispatcher, targetRegistry, () => { const browserHandler = new BrowserHandler(dispatcher.rootSession(), dispatcher, targetRegistry, () => {
if (silent) if (silent)
Services.startup.exitLastWindowClosingSurvivalArea(); 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); dispatcher.rootSession().registerHandler('Browser', browserHandler);
loadFrameScript(); loadFrameScript();

View file

@ -128,12 +128,14 @@ nsresult nsRemoteDebuggingPipe::Stop() {
#if defined(_WIN32) #if defined(_WIN32)
CancelIoEx(readHandle, nullptr); CancelIoEx(readHandle, nullptr);
CloseHandle(readHandle); CloseHandle(readHandle);
CloseHandle(writeHandle);
#else #else
shutdown(readFD, SHUT_RDWR); shutdown(readFD, SHUT_RDWR);
shutdown(writeFD, SHUT_RDWR);
#endif #endif
mReaderThread->Shutdown(); mReaderThread->Shutdown();
mReaderThread = nullptr; mReaderThread = nullptr;
mWriterThread->AsyncShutdown(); mWriterThread->Shutdown();
mWriterThread = nullptr; mWriterThread = nullptr;
return NS_OK; return NS_OK;
} }

View file

@ -125,13 +125,13 @@ class BrowserHandler {
} }
async close() { async close() {
this._onclose();
let browserWindow = Services.wm.getMostRecentWindow( let browserWindow = Services.wm.getMostRecentWindow(
"navigator:browser" "navigator:browser"
); );
if (browserWindow && browserWindow.gBrowserInit) { if (browserWindow && browserWindow.gBrowserInit) {
await browserWindow.gBrowserInit.idleTasksFinishedPromise; await browserWindow.gBrowserInit.idleTasksFinishedPromise;
} }
this._onclose();
Services.startup.quit(Ci.nsIAppStartup.eForceQuit); Services.startup.quit(Ci.nsIAppStartup.eForceQuit);
} }