Skip to content

Commit c550a7b

Browse files
authored
debug: auto recover from shifted tmpdirs in auto lauch (microsoft#184764)
I think this should fix microsoft/vscode-js-debug#1660
1 parent 5a55352 commit c550a7b

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

extensions/debug-auto-launch/src/extension.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { promises as fs } from 'fs';
77
import { createServer, Server } from 'net';
8+
import { dirname } from 'path';
89
import * as vscode from 'vscode';
910

1011
const enum State {
@@ -72,8 +73,7 @@ export function activate(context: vscode.ExtensionContext): void {
7273
e.affectsConfiguration(`${SETTING_SECTION}.${SETTING_STATE}`) ||
7374
[...SETTINGS_CAUSE_REFRESH].some(setting => e.affectsConfiguration(setting))
7475
) {
75-
updateAutoAttach(State.Disabled);
76-
updateAutoAttach(readCurrentState());
76+
refreshAutoAttachVars();
7777
}
7878
}),
7979
);
@@ -85,6 +85,11 @@ export async function deactivate(): Promise<void> {
8585
await destroyAttachServer();
8686
}
8787

88+
function refreshAutoAttachVars() {
89+
updateAutoAttach(State.Disabled);
90+
updateAutoAttach(readCurrentState());
91+
}
92+
8893
function getDefaultScope(info: ReturnType<vscode.WorkspaceConfiguration['inspect']>) {
8994
if (!info) {
9095
return vscode.ConfigurationTarget.Global;
@@ -204,8 +209,22 @@ async function createAttachServer(context: vscode.ExtensionContext) {
204209
return undefined;
205210
}
206211

207-
server = createServerInner(ipcAddress).catch(err => {
208-
console.error(err);
212+
server = createServerInner(ipcAddress).catch(async err => {
213+
console.error('[debug-auto-launch] Error creating auto attach server: ', err);
214+
215+
if (process.platform !== 'win32') {
216+
// On macOS, and perhaps some Linux distros, the temporary directory can
217+
// sometimes change. If it looks like that's the cause of a listener
218+
// error, automatically refresh the auto attach vars.
219+
try {
220+
await fs.access(dirname(ipcAddress));
221+
} catch {
222+
console.error('[debug-auto-launch] Refreshing variables from error');
223+
refreshAutoAttachVars();
224+
return undefined;
225+
}
226+
}
227+
209228
return undefined;
210229
});
211230

0 commit comments

Comments
 (0)