Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use localhost instead of 0.0.0.0 for all local socket servers #417

Merged
merged 48 commits into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ecc1ca9
Fix Microsoft/vscode#37627 (#1368)
octref Nov 3, 2017
7c5778c
Version 0.7.0 of extension (#1381)
DonJayamanne Nov 9, 2017
9d1bf82
Update README.md
DonJayamanne Nov 9, 2017
ffba179
Update README.md
DonJayamanne Nov 9, 2017
905c713
sync fork with upstream
DonJayamanne Nov 10, 2017
acc2109
fix readme
DonJayamanne Nov 10, 2017
d470523
Merge branch 'master' of https://github.com/Microsoft/vscode-python
DonJayamanne Nov 16, 2017
d392e8b
merged upstream
DonJayamanne Nov 16, 2017
92f775f
Merge remote-tracking branch 'upstream/master'
DonJayamanne Nov 20, 2017
32a6e53
Merge remote-tracking branch 'upstream/master'
DonJayamanne Nov 21, 2017
4b30f2c
Merge remote-tracking branch 'upstream/master'
DonJayamanne Nov 22, 2017
e396752
Merge remote-tracking branch 'upstream/master'
DonJayamanne Nov 22, 2017
eff4792
Merge remote-tracking branch 'upstream/master'
DonJayamanne Nov 28, 2017
4553c28
Merge remote-tracking branch 'upstream/master'
DonJayamanne Nov 28, 2017
3c6520a
Merge remote-tracking branch 'upstream/master'
DonJayamanne Nov 28, 2017
966e516
Merge remote-tracking branch 'upstream/master'
DonJayamanne Nov 28, 2017
63d2d65
Merge remote-tracking branch 'upstream/master'
DonJayamanne Nov 28, 2017
f6d469e
Merge remote-tracking branch 'upstream/master'
DonJayamanne Nov 28, 2017
029e055
Merge remote-tracking branch 'upstream/master'
DonJayamanne Nov 30, 2017
e8c71c0
Merge remote-tracking branch 'upstream/master'
DonJayamanne Nov 30, 2017
51cf9d2
Merge remote-tracking branch 'upstream/master'
DonJayamanne Dec 1, 2017
7aadc43
Merge remote-tracking branch 'upstream/master'
DonJayamanne Dec 1, 2017
f0f5c59
Merge remote-tracking branch 'upstream/master'
DonJayamanne Dec 4, 2017
b2b9da9
Merge remote-tracking branch 'upstream/master'
DonJayamanne Dec 4, 2017
30a4091
Merge remote-tracking branch 'upstream/master'
DonJayamanne Dec 5, 2017
b16d2f9
Merge remote-tracking branch 'upstream/master'
DonJayamanne Dec 6, 2017
c8db345
Merge remote-tracking branch 'upstream/master'
DonJayamanne Dec 7, 2017
0df7f16
Merge remote-tracking branch 'upstream/master'
DonJayamanne Dec 8, 2017
3ccc881
Merge remote-tracking branch 'upstream/master'
DonJayamanne Dec 9, 2017
bb0709e
Merge remote-tracking branch 'upstream/master'
DonJayamanne Dec 11, 2017
2c19004
Merge remote-tracking branch 'upstream/master'
DonJayamanne Dec 11, 2017
8f224ab
Merge remote-tracking branch 'upstream/master'
DonJayamanne Dec 11, 2017
41b7080
Merge remote-tracking branch 'upstream/master'
DonJayamanne Dec 12, 2017
dab38dc
Merge remote-tracking branch 'upstream/master'
DonJayamanne Dec 12, 2017
ae22dd4
Merge remote-tracking branch 'upstream/master'
DonJayamanne Dec 12, 2017
00198d3
add support for port and host configs in debugging and unit tests
DonJayamanne Dec 13, 2017
87e26f3
unit tests to ensure debugger port and hosts are used
DonJayamanne Dec 14, 2017
1943a64
added missing license header
DonJayamanne Dec 14, 2017
9c15f60
add delay for each test
DonJayamanne Dec 14, 2017
92971af
add start delay
DonJayamanne Dec 14, 2017
3255946
ignore erros
DonJayamanne Dec 14, 2017
00e3d0d
check how test fails
DonJayamanne Dec 14, 2017
6aa2048
check how test fails
DonJayamanne Dec 14, 2017
e9b148a
check how test fails
DonJayamanne Dec 14, 2017
021fcda
check how test fails
DonJayamanne Dec 14, 2017
8a6b84b
check how test fails
DonJayamanne Dec 14, 2017
d51141c
clean up
DonJayamanne Dec 14, 2017
dc6fb8e
fix code review comments
DonJayamanne Dec 15, 2017
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
1,127 changes: 1,024 additions & 103 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,16 @@
"type": "string",
"description": "Absolute path to a file containing environment variable definitions.",
"default": ""
},
"port": {
"type": "number",
"description": "Debug port (default is 0, resulting in the use of a dynamic port).",
"default": 0
},
"host": {
"type": "string",
"description": "IP Address of the of the local debug server (default is localhost or use 127.0.0.1).",
Copy link
Member

Choose a reason for hiding this comment

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

"IP address" and I would drop the "127.0.0.1" mention since the default works.

"default": "localhost"
}
}
},
Expand Down Expand Up @@ -1321,6 +1331,12 @@
"description": "Port number used for debugging of unittests.",
"scope": "resource"
},
"python.unitTest.debugHost": {
"type": "number",
"default": "localhost",
"description": "IP Address of the of the local unit test server (default is localhost or use 127.0.0.1).",
"scope": "resource"
},
"python.unitTest.cwd": {
"type": "string",
"default": null,
Expand Down Expand Up @@ -1567,6 +1583,7 @@
"tslint-microsoft-contrib": "^5.0.1",
"typescript": "^2.6.2",
"typescript-formatter": "^6.0.0",
"vscode": "^1.1.5"
"vscode": "^1.1.5",
"vscode-debugadapter-testsupport": "^1.25.0"
}
}
1 change: 1 addition & 0 deletions src/client/common/configSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface ISortImportSettings {
export interface IUnitTestSettings {
promptToConfigure: boolean;
debugPort: number;
debugHost?: string;
nosetestsEnabled: boolean;
nosetestPath: string;
nosetestArgs: string[];
Expand Down
40 changes: 18 additions & 22 deletions src/client/common/net/socket/socketServer.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
"use strict";

import * as net from "net";
import { EventEmitter } from 'events';
import * as net from 'net';
import { createDeferred } from '../../helpers';

export class SocketServer extends EventEmitter {
private socketServer: net.Server = null;
private socketServer: net.Server | undefined;
constructor() {
super();
}

public Stop() {
if (this.socketServer === null) { return; }
if (!this.socketServer) { return; }
try {
this.socketServer.close();
}
catch (ex) { }
this.socketServer = null;
// tslint:disable-next-line:no-empty
} catch (ex) { }
this.socketServer = undefined;
}

public Start(): Promise<number> {
public Start(options: { port?: number, host?: string } = {}): Promise<number> {
const def = createDeferred<number>();
this.socketServer = net.createServer(this.connectionListener.bind(this));

this.socketServer.listen(0, function (this: SocketServer) {
def.resolve(this.socketServer.address().port);
}.bind(this));
const port = typeof options.port === 'number' ? options.port! : 0;
const host = typeof options.host === 'string' ? options.host! : 'localhost';
this.socketServer!.listen({ port, host }, () => {
def.resolve(this.socketServer!.address().port);
});

this.socketServer.on("error", ex => {
this.socketServer!.on('error', ex => {
console.error('Error in Socket Server', ex);
if (def.completed) {
// Ooops
debugger;
}
const msg = `Failed to start the socket server. (Error: ${ex.message})`;

def.reject(msg);
Expand All @@ -41,14 +37,14 @@ export class SocketServer extends EventEmitter {
}

private connectionListener(client: net.Socket) {
client.on("close", function () {
client.on('close', () => {
this.emit('close', client);
}.bind(this));
client.on("data", function (data: Buffer) {
});
client.on('data', (data: Buffer) => {
this.emit('data', client, data);
}.bind(this));
});

client.on("timeout", d => {
client.on('timeout', d => {
// let msg = "Debugger client timedout, " + d;
});
}
Expand Down
37 changes: 20 additions & 17 deletions src/client/debugger/Common/Contracts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"use strict";
import * as net from "net";
// tslint:disable:interface-name member-access no-single-line-block-comment no-any no-stateless-class member-ordering prefer-method-signature

'use strict';
import { ChildProcess } from 'child_process';
import { DebugProtocol } from "vscode-debugprotocol";
import { OutputEvent } from "vscode-debugadapter";
import * as net from 'net';
import { OutputEvent } from 'vscode-debugadapter';
import { DebugProtocol } from 'vscode-debugprotocol';

export class TelemetryEvent extends OutputEvent {
body: {
Expand All @@ -14,25 +16,25 @@ export class TelemetryEvent extends OutputEvent {
data?: any;
};
constructor(output: string, data?: any) {
super(output, "telemetry");
super(output, 'telemetry');
if (data) {
this.body.data = data;
}
}
}
export const DjangoApp = "DJANGO";
export const DjangoApp = 'DJANGO';
export enum DebugFlags {
None = 0,
IgnoreCommandBursts = 1
}

export class DebugOptions {
public static get WaitOnAbnormalExit(): string { return "WaitOnAbnormalExit"; }
public static get WaitOnNormalExit(): string { return "WaitOnNormalExit"; }
public static get RedirectOutput(): string { return "RedirectOutput"; }
public static get DjangoDebugging(): string { return "DjangoDebugging"; }
public static get DebugStdLib(): string { return "DebugStdLib"; }
public static get BreakOnSystemExitZero(): string { return "BreakOnSystemExitZero"; }
public static get WaitOnAbnormalExit(): string { return 'WaitOnAbnormalExit'; }
public static get WaitOnNormalExit(): string { return 'WaitOnNormalExit'; }
public static get RedirectOutput(): string { return 'RedirectOutput'; }
public static get DjangoDebugging(): string { return 'DjangoDebugging'; }
public static get DebugStdLib(): string { return 'DebugStdLib'; }
public static get BreakOnSystemExitZero(): string { return 'BreakOnSystemExitZero'; }
}

export interface ExceptionHandling {
Expand All @@ -55,7 +57,9 @@ export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArgum
env?: Object;
envFile: string;
exceptionHandling?: ExceptionHandling;
console?: "none" | "integratedTerminal" | "externalTerminal";
console?: 'none' | 'integratedTerminal' | 'externalTerminal';
port?: number;
host?: string;
}

export interface AttachRequestArguments extends DebugProtocol.AttachRequestArguments {
Expand All @@ -76,7 +80,8 @@ export enum FrameKind {
None,
Python,
Django
};
}

export enum enum_EXCEPTION_STATE {
BREAK_MODE_NEVER = 0,
BREAK_MODE_ALWAYS = 1,
Expand All @@ -99,7 +104,7 @@ export enum PythonEvaluationResultFlags {
MethodCall = 2,
SideEffects = 4,
Raw = 8,
HasRawRepr = 16,
HasRawRepr = 16
}

export interface IPythonProcess extends NodeJS.EventEmitter {
Expand Down Expand Up @@ -138,14 +143,12 @@ export interface IPythonEvaluationResult {
Frame: IPythonStackFrame;
}


export interface IPythonModule {
ModuleId: number;
Name: string;
Filename: string;
}


export interface IPythonThread {
IsWorkerThread: boolean;
Process: IPythonProcess;
Expand Down
2 changes: 1 addition & 1 deletion src/client/debugger/DebugClients/LocalDebugClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class LocalDebugClient extends DebugClient {

public CreateDebugServer(pythonProcess: IPythonProcess): BaseDebugServer {
this.pythonProcess = pythonProcess;
this.debugServer = new LocalDebugServer(this.debugSession, this.pythonProcess);
this.debugServer = new LocalDebugServer(this.debugSession, this.pythonProcess, this.args);
return this.debugServer;
}

Expand Down
13 changes: 6 additions & 7 deletions src/client/debugger/DebugServers/DebugServerFactory.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {BaseDebugServer} from "./BaseDebugServer";
import {LocalDebugServer} from "./LocalDebugServer";
import {RemoteDebugServer} from "./RemoteDebugServer";
import {DebugSession, OutputEvent} from "vscode-debugadapter";
import {IPythonProcess, IDebugServer} from "../Common/Contracts";
import { DebugSession } from 'vscode-debugadapter';
import { IPythonProcess, LaunchRequestArguments } from '../Common/Contracts';
import { BaseDebugServer } from './BaseDebugServer';
import { LocalDebugServer } from './LocalDebugServer';

export function CreateDebugServer(debugSession: DebugSession, pythonProcess: IPythonProcess): BaseDebugServer {
return new LocalDebugServer(debugSession, pythonProcess);
export function CreateDebugServer(debugSession: DebugSession, pythonProcess: IPythonProcess, args: LaunchRequestArguments): BaseDebugServer {
return new LocalDebugServer(debugSession, pythonProcess, args);
}
18 changes: 10 additions & 8 deletions src/client/debugger/DebugServers/LocalDebugServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
import * as net from 'net';
import { EOL } from 'os';
import { DebugSession, OutputEvent } from 'vscode-debugadapter';
import { IDebugServer, IPythonProcess } from '../Common/Contracts';
import { IDebugServer, IPythonProcess, LaunchRequestArguments } from '../Common/Contracts';
import { BaseDebugServer } from './BaseDebugServer';

export class LocalDebugServer extends BaseDebugServer {
private debugSocketServer: net.Server = null;
private debugSocketServer: net.Server | undefined;

constructor(debugSession: DebugSession, pythonProcess: IPythonProcess) {
constructor(debugSession: DebugSession, pythonProcess: IPythonProcess, private args: LaunchRequestArguments) {
super(debugSession, pythonProcess);
}

public Stop() {
if (this.debugSocketServer === null) { return; }
if (!this.debugSocketServer) { return; }
try {
this.debugSocketServer.close();
// tslint:disable-next-line:no-empty
} catch { }
this.debugSocketServer = null;
this.debugSocketServer = undefined;
}

public async Start(): Promise<IDebugServer> {
Expand Down Expand Up @@ -61,7 +61,7 @@ export class LocalDebugServer extends BaseDebugServer {
reject(msg);
});
});
this.debugSocketServer.on('error', ex => {
this.debugSocketServer!.on('error', ex => {
const exMessage = JSON.stringify(ex);
let msg = '';
// tslint:disable-next-line:no-any
Expand All @@ -77,8 +77,10 @@ export class LocalDebugServer extends BaseDebugServer {
reject(msg);
});

this.debugSocketServer.listen(0, () => {
const server = this.debugSocketServer.address();
const port = typeof this.args.port === 'number' ? this.args.port! : 0;
const host = typeof this.args.host === 'string' && this.args.host.trim().length > 0 ? this.args.host!.trim() : 'localhost';
this.debugSocketServer!.listen({ port, host }, () => {
const server = this.debugSocketServer!.address();
resolve({ port: server.port });
});
});
Expand Down
24 changes: 0 additions & 24 deletions src/client/jedi/commands.ts

This file was deleted.

Loading