From 458c4cff39a1d7b7419defb445e886d678e7aad8 Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Wed, 6 Oct 2021 09:45:53 -0700 Subject: [PATCH] improvement for the editor crash issue (#17278) * handle the query editor crash issue * update message --- .../contrib/query/browser/queryResultsView.ts | 13 ++++++++++++- .../workbench/services/query/common/queryRunner.ts | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/sql/workbench/contrib/query/browser/queryResultsView.ts b/src/sql/workbench/contrib/query/browser/queryResultsView.ts index fc07160d0b..c1b6417ce2 100644 --- a/src/sql/workbench/contrib/query/browser/queryResultsView.ts +++ b/src/sql/workbench/contrib/query/browser/queryResultsView.ts @@ -23,6 +23,8 @@ import { IThemeService } from 'vs/platform/theme/common/themeService'; import { Event } from 'vs/base/common/event'; import { URI } from 'vs/base/common/uri'; import { attachTabbedPanelStyler } from 'sql/workbench/common/styler'; +import { INotificationService } from 'vs/platform/notification/common/notification'; +import { ILogService } from 'vs/platform/log/common/log'; class MessagesView extends Disposable implements IPanelView { private messagePanel: MessagePanel; @@ -170,7 +172,9 @@ export class QueryResultsView extends Disposable { container: HTMLElement, @IThemeService themeService: IThemeService, @IInstantiationService private instantiationService: IInstantiationService, - @IQueryModelService private queryModelService: IQueryModelService + @IQueryModelService private queryModelService: IQueryModelService, + @INotificationService private notificationService: INotificationService, + @ILogService private logService: ILogService ) { super(); this.resultsTab = this._register(new ResultsTab(instantiationService)); @@ -312,6 +316,13 @@ export class QueryResultsView extends Disposable { dynamicTab.captureState(input.state.dynamicModelViewTabsState); }); let info = this.queryModelService._getQueryInfo(input.uri) || this.queryModelService._getQueryInfo(URI.parse(input.uri).toString(true)); + + if (info?.queryRunner?.isDisposed) { + this.logService.error(`The query runner for '${input.uri}' has been disposed.`); + this.notificationService.error(nls.localize('queryResults.queryEditorCrashError', "The query editor ran into an issue and has stopped working. Please save and reopen it.")); + return; + } + if (info?.queryRunner) { this.setQueryRunner(info.queryRunner); } else { diff --git a/src/sql/workbench/services/query/common/queryRunner.ts b/src/sql/workbench/services/query/common/queryRunner.ts index bf4031bf55..e946b12f01 100644 --- a/src/sql/workbench/services/query/common/queryRunner.ts +++ b/src/sql/workbench/services/query/common/queryRunner.ts @@ -104,6 +104,12 @@ export default class QueryRunner extends Disposable { return this._hasCompleted; } + private _isDisposed: boolean = false; + + get isDisposed(): boolean { + return this._isDisposed; + } + /** * For public use only, for private use, directly access the member */ @@ -417,8 +423,10 @@ export default class QueryRunner extends Disposable { } public override dispose() { + this.logService.info(`Disposing the query runner of: '${this.uri}'', call stack: ${new Error().stack}`); this._batchSets = undefined!; super.dispose(); + this._isDisposed = true; } public changeConnectionUri(oldUri: string, newUri: string): Promise {