Skip to content

Commit dcdc634

Browse files
committed
Ensure cert-installing firefox instances are cleaned up on shutdown
1 parent 8a88d60 commit dcdc634

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/interceptors/fresh-firefox.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const canAccess = (path: string) =>
2121

2222
const FIREFOX_PREF_REGEX = /\w+_pref\("([^"]+)", (.*)\);/
2323

24+
let certInstallBrowser: BrowserInstance | undefined;
2425
let browsers: _.Dictionary<BrowserInstance> = {};
2526

2627
export class FreshFirefox implements Interceptor {
@@ -127,15 +128,18 @@ export class FreshFirefox implements Interceptor {
127128
await certCheckServer.start();
128129
const certInstalled = certCheckServer.waitForSuccess().catch(reportError);
129130

130-
const browser = await this.startFirefox(certCheckServer);
131-
browser.process.once('exit', () => certCheckServer.stop());
131+
certInstallBrowser = await this.startFirefox(certCheckServer);
132+
certInstallBrowser.process.once('exit', () => {
133+
certCheckServer.stop();
134+
certInstallBrowser = undefined;
135+
});
132136
await certInstalled;
133137
await delay(100); // Tiny delay, so firefox can do initial setup tasks
134-
browser.stop();
138+
certInstallBrowser.stop();
135139
}
136140

137141
async activate(proxyPort: number) {
138-
if (this.isActive(proxyPort)) return;
142+
if (this.isActive(proxyPort) || !!certInstallBrowser) return;
139143

140144
const firefoxProfile = path.join(this.config.configPath, 'firefox-profile');
141145
const firefoxPrefsFile = path.join(firefoxProfile, 'prefs.js');
@@ -205,5 +209,9 @@ export class FreshFirefox implements Interceptor {
205209
await Promise.all(
206210
Object.keys(browsers).map((proxyPort) => this.deactivate(proxyPort))
207211
);
212+
if (certInstallBrowser) {
213+
certInstallBrowser.stop();
214+
return new Promise((resolve) => certInstallBrowser!.process.once('exit', resolve));
215+
}
208216
}
209217
};

0 commit comments

Comments
 (0)