Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/client/debugger/mainV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { BaseDebugServer } from './DebugServers/BaseDebugServer';
import { initializeIoc } from './serviceRegistry';
import { IDebugStreamProvider, IProtocolLogger, IProtocolMessageWriter, IProtocolParser } from './types';

const DEBUGGER_CONNECT_TIMEOUT = 10000;

export class PythonDebugger extends DebugSession {
public debugServer?: BaseDebugServer;
public debugClient?: DebugClient<{}>;
Expand Down Expand Up @@ -179,9 +181,8 @@ export class PythonDebugger extends DebugSession {
const enableLogging = args.logToFile === true;
this.emit('_py_enable_protocol_logging', enableLogging);

this.emit('_py_pre_launch');

this.startPTVSDDebugger(args)
.then(() => this.waitForDebuggerConnection())
.then(() => this.sendResponse(response))
.catch(ex => {
const message = this.getErrorUserFriendlyMessage(args, ex) || 'Debug Error';
Expand All @@ -194,6 +195,21 @@ export class PythonDebugger extends DebugSession {
const serverInfo = await this.debugServer!.Start();
return launcher.LaunchApplicationToDebug(serverInfo);
}
private async waitForDebuggerConnection() {
return new Promise<void>(async (resolve, reject) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make this configurable

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

let rejected = false;
const timeout = setTimeout(() => {
rejected = true;
reject(new Error('Timeout waiting for debugger connection'));
}, DEBUGGER_CONNECT_TIMEOUT);

await this.debugServer!.client;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this throws, do we need to unref still? Maybe finally ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

timeout.unref();
if (!rejected) {
resolve();
}
});
}
private getErrorUserFriendlyMessage(launchArgs: LaunchRequestArguments, error: any): string | undefined {
if (!error) {
return;
Expand Down