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
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

View file

@ -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();

View file

@ -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;
}

View file

@ -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);
}