Skip to content

Commit

Permalink
fix: wait for output to flush before shutting down
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Jul 10, 2020
1 parent b5d31bc commit 02f9147
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
32 changes: 19 additions & 13 deletions src/adapter/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@

import * as nls from 'vscode-nls';
import Cdp from '../cdp/api';
import { EventEmitter } from '../common/events';
import { HrTime } from '../common/hrnow';
import { ILogger, LogTag } from '../common/logging';
import { delay, getDeferred, IDeferred } from '../common/promiseUtil';
import * as sourceUtils from '../common/sourceUtils';
import * as urlUtils from '../common/urlUtils';
import { fileUrlToAbsolutePath } from '../common/urlUtils';
import { AnyLaunchConfiguration, OutputSource } from '../configuration';
import Dap from '../dap/api';
import * as errors from '../dap/errors';
import * as ProtocolError from '../dap/protocolError';
import { IBreakpointPathAndId } from '../targets/targets';
import { BreakpointManager, EntryBreakpointMode } from './breakpoints';
import { UserDefinedBreakpoint } from './breakpoints/userDefinedBreakpoint';
import { ICompletions } from './completions';
import { CustomBreakpointId, customBreakpoints } from './customBreakpoints';
import { IEvaluator } from './evaluator';
import * as messageFormat from './messageFormat';
import * as objectPreview from './objectPreview';
import { AnyObject } from './objectPreview/betterTypes';
import { SmartStepper } from './smartStepping';
import { IPreferredUiLocation, Source, SourceContainer, IUiLocation, base1To0 } from './sources';
import { base1To0, IPreferredUiLocation, IUiLocation, Source, SourceContainer } from './sources';
import { StackFrame, StackTrace } from './stackTrace';
import { VariableStore, IVariableStoreDelegate } from './variables';
import { previewThis } from './templates/previewThis';
import { UserDefinedBreakpoint } from './breakpoints/userDefinedBreakpoint';
import { ILogger, LogTag } from '../common/logging';
import { AnyObject } from './objectPreview/betterTypes';
import { IEvaluator } from './evaluator';
import {
serializeForClipboardTmpl,
serializeForClipboard,
serializeForClipboardTmpl,
} from './templates/serializeForClipboard';
import { EventEmitter } from '../common/events';
import { IBreakpointPathAndId } from '../targets/targets';
import { fileUrlToAbsolutePath } from '../common/urlUtils';
import { HrTime } from '../common/hrnow';
import { IVariableStoreDelegate, VariableStore } from './variables';

const localize = nls.loadMessageBundle();

Expand Down Expand Up @@ -747,16 +747,22 @@ export class Thread implements IVariableStoreDelegate {
this._onThreadResumed();
}

dispose() {
/**
* @inheritdoc
*/
async dispose() {
this._removeAllScripts(true /* silent */);
for (const [debuggerId, thread] of Thread._allThreadsByDebuggerId) {
if (thread === this) Thread._allThreadsByDebuggerId.delete(debuggerId);
}

this._executionContextsCleared();

// Output flush already has a timeout, no need for another one here
await this._serializedOutput;

// Send 'exited' after all other thread-releated events
this._dap.with(dap =>
await this._dap.with(dap =>
dap.thread({
reason: 'exited',
threadId: this.id,
Expand Down
28 changes: 14 additions & 14 deletions src/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import { Container } from 'inversify';
import * as os from 'os';
import { CancellationToken } from 'vscode';
import * as nls from 'vscode-nls';
import { getAsyncStackPolicy, IAsyncStackPolicy } from './adapter/asyncStackPolicy';
import { DebugAdapter } from './adapter/debugAdapter';
import { SelfProfile } from './adapter/selfProfile';
import { Thread } from './adapter/threads';
import { CancellationTokenSource } from './common/cancellation';
import { IDisposable, EventEmitter } from './common/events';
import { LogTag, ILogger, resolveLoggerOptions } from './common/logging';
import { EventEmitter, IDisposable } from './common/events';
import { ILogger, LogTag, resolveLoggerOptions } from './common/logging';
import { mapValues } from './common/objUtils';
import { delay } from './common/promiseUtil';
import * as urlUtils from './common/urlUtils';
import {
AnyLaunchConfiguration,
Expand All @@ -20,21 +26,15 @@ import {
import Dap from './dap/api';
import DapConnection from './dap/connection';
import { ProtocolError } from './dap/protocolError';
import { createTargetContainer, provideLaunchParams } from './ioc';
import { disposeContainer, IInitializeParams } from './ioc-extras';
import { ITargetOrigin } from './targets/targetOrigin';
import { ILauncher, ILaunchResult, ITarget } from './targets/targets';
import { ITelemetryReporter } from './telemetry/telemetryReporter';
import {
filterErrorsReportedToTelemetry,
installUnhandledErrorReporter,
} from './telemetry/unhandledErrorReporter';
import { ITargetOrigin } from './targets/targetOrigin';
import { IAsyncStackPolicy, getAsyncStackPolicy } from './adapter/asyncStackPolicy';
import { ITelemetryReporter } from './telemetry/telemetryReporter';
import { mapValues } from './common/objUtils';
import * as os from 'os';
import { delay } from './common/promiseUtil';
import { Container } from 'inversify';
import { createTargetContainer, provideLaunchParams } from './ioc';
import { disposeContainer, IInitializeParams } from './ioc-extras';
import { SelfProfile } from './adapter/selfProfile';

const localize = nls.loadMessageBundle();

Expand Down Expand Up @@ -449,11 +449,11 @@ export class Binder implements IDisposable {
}
}

_releaseTarget(target: ITarget, terminateArgs: Dap.TerminatedEventParams = {}) {
async _releaseTarget(target: ITarget, terminateArgs: Dap.TerminatedEventParams = {}) {
const data = this._threads.get(target);
if (!data) return;
this._threads.delete(target);
data.thread.dispose();
await data.thread.dispose();
data.debugAdapter.dap.terminated(terminateArgs);
data.debugAdapter.dispose();
this._delegate.releaseDap(target);
Expand Down

0 comments on commit 02f9147

Please sign in to comment.