Skip to content

Commit

Permalink
Fix hung on close + optional temp folder create (only if breakpoints …
Browse files Browse the repository at this point in the history
…pulling enabled) + cleanup temp folder on close
  • Loading branch information
A-Kovalev-Playrix committed Dec 7, 2022
1 parent abdb816 commit b6b2b13
Showing 1 changed file with 30 additions and 35 deletions.
65 changes: 30 additions & 35 deletions extension/debugPipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,10 @@ export function createFifoPipe(): DebugPipe {
const outputPipePath = `/tmp/lldbg_out_${pipeId}`;
const inputPipePath = `/tmp/lldbg_in_${pipeId}`;
let pullPipePath = "";

const appPrefix = 'lldebugger';
try {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), appPrefix));
pullPipePath = path.join(tmpDir, "pull.txt");
} catch {
// handle error
}

let outputFd: number | null;
let inputFd: number | null;
let pullFd: number | null;
let debuggerTmpDir = "";
let outputFd: number | null = null;
let inputFd: number | null = null;
let pullFd: number | null = null;
let inputStream: fs.WriteStream | null = null;
let pullStream: fs.WriteStream | null = null;
let onErrorCallback: ((err: unknown) => void) | null = null;
Expand Down Expand Up @@ -163,19 +155,20 @@ export function createFifoPipe(): DebugPipe {
onErrorCallback = onError;
}

fs.open(
pullPipePath,
fs.constants.O_WRONLY | fs.constants.O_CREAT,
(fdErr, fd) => {
if (fdErr) {
onError(`error opening input pipe: ${fdErr}`);
return;
}
const appPrefix = "lldebugger";
try {
debuggerTmpDir = fs.mkdtempSync(path.join(os.tmpdir(), appPrefix));
pullPipePath = path.join(debuggerTmpDir, "pull.txt");

pullFd = fd;
pullStream = fs.createWriteStream(null as unknown as fs.PathLike, {fd});
}
);
const fd = fs.openSync(
pullPipePath,
fs.constants.O_WRONLY | fs.constants.O_CREAT
);
pullFd = fd;
pullStream = fs.createWriteStream(null as unknown as fs.PathLike, {fd});
} catch (e: unknown) {
onErrorCallback(e);
}
},

close: () => {
Expand Down Expand Up @@ -203,17 +196,19 @@ export function createFifoPipe(): DebugPipe {
}
);
}
if (pullFd !== null) {
fs.close(pullFd);
pullFd = null;
fs.rm(
pullPipePath,
err => {
if (err) {
onErrorCallback?.(`error removing pull file '${pullPipePath}': ${err}`);
}
}
);
inputStream = null;
try {
if (pullFd !== null) {
fs.close(pullFd);
fs.rmSync(pullPipePath);
pullFd = null;
}
pullStream = null;
if (debuggerTmpDir.length > 0) {
fs.rmdirSync(debuggerTmpDir);
}
} catch (e: unknown) {
onErrorCallback?.(e);
}
},

Expand Down

0 comments on commit b6b2b13

Please sign in to comment.