1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Stop file system watchers on application quit to prevent exit code !== 0 (#7504)

* fix: Dispose the kubeconfig watcher when application quits

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* fix: Dispose the extension watcher when application quits

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

---------

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2023-04-05 16:34:32 +03:00 committed by Sebastian Malton
parent 807f98ed1b
commit a3716baaf0
3 changed files with 47 additions and 4 deletions

View File

@ -17,7 +17,7 @@ import { requestInitialExtensionDiscovery } from "../../renderer/ipc";
import type { ReadJson } from "../../common/fs/read-json-file.injectable";
import type { Logger } from "../../common/logger";
import type { PathExists } from "../../common/fs/path-exists.injectable";
import type { Watch } from "../../common/fs/watch/watch.injectable";
import type { Watch, Watcher } from "../../common/fs/watch/watch.injectable";
import type { Stats } from "fs";
import type { LStat } from "../../common/fs/lstat.injectable";
import type { ReadDirectory } from "../../common/fs/read-directory.injectable";
@ -149,6 +149,8 @@ export class ExtensionDiscovery {
});
}
private _watch: Watcher<false>|undefined;
/**
* Watches for added/removed local extensions.
* Dependencies are installed automatically after an extension folder is copied.
@ -159,7 +161,7 @@ export class ExtensionDiscovery {
// Wait until .load() has been called and has been resolved
await this.whenLoaded;
this.dependencies.watch(this.localFolderPath, {
this._watch = this.dependencies.watch(this.localFolderPath, {
// For adding and removing symlinks to work, the depth has to be 1.
depth: 1,
ignoreInitial: true,
@ -179,6 +181,12 @@ export class ExtensionDiscovery {
.on("unlink", this.handleWatchUnlinkEvent);
}
async stopWatchingExtensions() {
this.dependencies.logger.info(`${logModule} stopping the watch for extensions`);
await this._watch?.close();
}
handleWatchFileAdd = async (manifestPath: string): Promise<void> => {
// e.g. "foo/package.json"
const relativePath = this.dependencies.getRelativePath(this.localFolderPath, manifestPath);

View File

@ -0,0 +1,27 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { beforeQuitOfBackEndInjectionToken } from "../../main/start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
import extensionDiscoveryInjectable from "./extension-discovery.injectable";
const stopWatchingExtensionsOnQuitInjectable = getInjectable({
id: "stop-watching-extensions-on-quit",
instantiate: (di) => {
const extensionDiscovery = di.inject(extensionDiscoveryInjectable);
return {
id: "stop-watching-extensions-on-quit",
run: async () => {
await extensionDiscovery.stopWatchingExtensions();
},
};
},
injectionToken: beforeQuitOfBackEndInjectionToken,
});
export default stopWatchingExtensionsOnQuitInjectable;

View File

@ -98,11 +98,19 @@ export class KubeconfigSyncManager {
@action
protected stopOldSync(filePath: string): void {
if (!this.sources.delete(filePath)) {
// already stopped
const source = this.sources.get(filePath);
// already stopped
if (!source) {
return this.dependencies.logger.debug(`no syncing file/folder to stop`, { filePath });
}
const [, disposer] = source;
disposer();
this.sources.delete(filePath);
this.dependencies.logger.info(`stopping sync of file/folder`, { filePath });
this.dependencies.logger.debug(`${this.sources.size} files/folders watched`, { files: Array.from(this.sources.keys()) });
}