Skip to content

Commit c0acfe7

Browse files
Fix Linux, 'EventType' declaration, and add '_isClosed'
- Added code to unlink the unix domain socket (in case there is one around from a previous reboot). - I forgot that TypeScript enums don't behave quite like what I wanted. This switches from an enum to a module. - Fixes DebugEventListener to cleanup only once. - Handle errors in DebugEventListener
1 parent 059a845 commit c0acfe7

File tree

4 files changed

+63
-31
lines changed

4 files changed

+63
-31
lines changed

src/assets.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -541,27 +541,10 @@ function doesAnyAssetExist(generator: AssetGenerator) {
541541
});
542542
}
543543

544-
function deleteAsset(path: string) {
545-
return new Promise<void>((resolve, reject) => {
546-
fs.exists(path, exists => {
547-
if (exists) {
548-
// TODO: Should we check after unlinking to see if the file still exists?
549-
fs.unlink(path, err => {
550-
if (err) {
551-
return reject(err);
552-
}
553-
554-
resolve();
555-
});
556-
}
557-
});
558-
});
559-
}
560-
561544
function deleteAssets(generator: AssetGenerator) {
562545
return Promise.all([
563-
deleteAsset(generator.launchJsonPath),
564-
deleteAsset(generator.tasksJsonPath)
546+
util.deleteIfExists(generator.launchJsonPath),
547+
util.deleteIfExists(generator.tasksJsonPath)
565548
]);
566549
}
567550

src/common.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,25 @@ export function fileExists(filePath: string): Promise<boolean> {
7373
});
7474
}
7575

76+
export function deleteIfExists(filePath: string): Promise<void> {
77+
return fileExists(filePath)
78+
.then((exists: boolean) => {
79+
return new Promise<void>((resolve, reject) => {
80+
if (!exists) {
81+
resolve();
82+
}
83+
84+
fs.unlink(filePath, err => {
85+
if (err) {
86+
return reject(err);
87+
}
88+
89+
resolve();
90+
});
91+
});
92+
});
93+
}
94+
7695
export enum InstallFileType {
7796
Begin,
7897
Lock

src/coreclr-debug/debuggerEventsProtocol.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
//
1111
// All messages are sent as UTF-8 JSON text with a tailing '\n'
1212
export namespace DebuggerEventsProtocol {
13-
export enum EventType {
13+
export module EventType {
1414
// Indicates that the vsdbg-ui has received the attach or launch request and is starting up
15-
starting,
15+
export const Starting = "starting";
1616
// Indicates that vsdbg-ui has successfully launched the specified process.
1717
// The ProcessLaunchedEvent interface details the event payload.
18-
processLaunched,
18+
export const ProcessLaunched = "processLaunched";
1919
// Debug session is ending
20-
debuggingStopped
21-
}
20+
export const DebuggingStopped = "debuggingStopped";
21+
};
2222

2323
export interface DebuggerEvent {
24-
eventType: EventType;
24+
// Contains one of the 'DebuggerEventsProtocol.EventType' values
25+
eventType: string;
2526
}
2627

2728
export interface ProcessLaunchedEvent extends DebuggerEvent {

src/features/dotnetTest.ts

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ class DebugEventListener {
191191
_serverSocket : net.Server;
192192
_pipePath : string;
193193
_outputChannel : vscode.OutputChannel;
194+
_isClosed: boolean = false;
194195

195196
constructor() {
196197
// NOTE: The max pipe name on OSX is fairly small, so this name shouldn't bee too long.
@@ -211,8 +212,6 @@ class DebugEventListener {
211212
DebugEventListener.s_activeInstance.close();
212213
}
213214
DebugEventListener.s_activeInstance = this;
214-
215-
// TODO: On Unix do we need to unlink file if it exists already?
216215

217216
this._serverSocket = net.createServer((socket: net.Socket) => {
218217
socket.on('data', (buffer: Buffer) => {
@@ -225,7 +224,9 @@ class DebugEventListener {
225224
return;
226225
}
227226

228-
if (event.eventType === DebuggerEventsProtocol.EventType.debuggingStopped) {
227+
if (event.eventType === DebuggerEventsProtocol.EventType.ProcessLaunched) {
228+
// TODO: notify OmniSharp
229+
} else if (event.eventType === DebuggerEventsProtocol.EventType.DebuggingStopped) {
229230
this.fireDebuggingStopped();
230231
}
231232
});
@@ -235,9 +236,20 @@ class DebugEventListener {
235236
});
236237
});
237238

238-
return new Promise<void>((resolve, reject) => {
239-
this._serverSocket.listen(this._pipePath, () => {
240-
resolve();
239+
return this.removeSocketFileIfExists().then(() => {
240+
return new Promise<void>((resolve, reject) => {
241+
let isStarted: boolean = false;
242+
this._serverSocket.on('error', (err: Error) => {
243+
if (!isStarted) {
244+
reject(err.message);
245+
} else {
246+
this._outputChannel.appendLine("Warning: Communications error on debugger event channel. " + err.message);
247+
}
248+
});
249+
this._serverSocket.listen(this._pipePath, () => {
250+
isStarted = true;
251+
resolve();
252+
});
241253
});
242254
});
243255
}
@@ -250,15 +262,32 @@ class DebugEventListener {
250262
if (this === DebugEventListener.s_activeInstance) {
251263
DebugEventListener.s_activeInstance = null;
252264
}
265+
if (this._isClosed) {
266+
return;
267+
}
268+
this._isClosed = true;
253269

254270
if (this._serverSocket !== null) {
255271
this._serverSocket.close();
256272
}
257273
}
258274

259275
private fireDebuggingStopped() : void {
276+
if (this._isClosed) {
277+
return;
278+
}
279+
260280
// TODO: notify omniSharp
261281

262282
this.close();
263283
}
284+
285+
private removeSocketFileIfExists() : Promise<void> {
286+
if (os.platform() === 'win32') {
287+
// Win32 doesn't use the file system for pipe names
288+
return Promise.resolve();
289+
} else {
290+
return utils.deleteIfExists(this._pipePath);
291+
}
292+
}
264293
}

0 commit comments

Comments
 (0)