From 22dd214678739e71bf51fcba7697e98f33ce191d Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 10 Mar 2016 19:01:37 +0100 Subject: [PATCH] watcher: do not blindly try to restart a crashing watcher until the end of days --- .../files/node/watcher/unix/watcherService.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/services/files/node/watcher/unix/watcherService.ts b/src/vs/workbench/services/files/node/watcher/unix/watcherService.ts index f3860364699..862075de7f0 100644 --- a/src/vs/workbench/services/files/node/watcher/unix/watcherService.ts +++ b/src/vs/workbench/services/files/node/watcher/unix/watcherService.ts @@ -25,10 +25,14 @@ export class WatcherService { } export class FileWatcher { + private static MAX_RESTARTS = 5; + private isDisposed: boolean; + private restartCounter: number; constructor(private basePath: string, private ignored: string[], private eventEmitter: IEventService, private errorLogger: (msg: string) => void, private verboseLogging: boolean) { this.isDisposed = false; + this.restartCounter = 0; } public startWatching(): () => void { @@ -55,9 +59,15 @@ export class FileWatcher { }, (events: IRawFileChange[]) => this.onRawFileEvents(events)).done(() => { // our watcher app should never be completed because it keeps on watching. being in here indicates - // that the watcher process died and we want to restart it here. + // that the watcher process died and we want to restart it here. we only do it a max number of times if (!this.isDisposed) { - this.startWatching(); + if (this.restartCounter <= FileWatcher.MAX_RESTARTS) { + this.errorLogger('Watcher terminated unexpectedly and is restarted again...'); + this.restartCounter++; + this.startWatching(); + } else { + this.errorLogger('Watcher failed to start after retrying for some time, giving up. Please report this as a bug report!'); + } } }, this.errorLogger); -- GitLab