Skip to content

Commit 096d858

Browse files
committed
fix: enforce two-stage verification for Unix process candidates
- Unix branch was using only string matching to add PIDs to candidates - Now validates each PID with isDeepnoteRelatedProcess() before adding - Added re-verification in kill/lock loop before any action - Matches Windows two-stage verification pattern - Prevents false positives from ps output string matching - Ensures only verified deepnote-related processes are considered - Adds safety check in case process changes between detection and action
1 parent 2345dfc commit 096d858

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/kernels/deepnote/deepnoteServerStarter.node.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -969,18 +969,22 @@ export class DeepnoteServerStarter implements IDeepnoteServerStarter, IExtension
969969
// - deepnote_toolkit server (main server process)
970970
// - pylsp (Python LSP server child process)
971971
// - jupyter (Jupyter server child process)
972-
const isDeepnoteRelated =
972+
const matchesPattern =
973973
(line.includes('deepnote_toolkit') && line.includes('server')) ||
974974
(line.includes('pylsp') && line.includes('2087')) || // LSP server on port 2087
975975
(line.includes('jupyter') && line.includes('deepnote'));
976976

977-
if (isDeepnoteRelated) {
977+
if (matchesPattern) {
978978
// Unix format: user PID ...
979979
const parts = line.trim().split(/\s+/);
980980
if (parts.length > 1) {
981981
const pid = parseInt(parts[1], 10);
982982
if (!isNaN(pid)) {
983-
candidatePids.push(pid);
983+
// Validate with isDeepnoteRelatedProcess before adding to candidates
984+
const isDeepnoteRelated = await this.isDeepnoteRelatedProcess(pid);
985+
if (isDeepnoteRelated) {
986+
candidatePids.push(pid);
987+
}
984988
}
985989
}
986990
}
@@ -996,6 +1000,14 @@ export class DeepnoteServerStarter implements IDeepnoteServerStarter, IExtension
9961000

9971001
// Check each process to determine if it should be killed
9981002
for (const pid of candidatePids) {
1003+
// Re-verify it's deepnote-related before any kill/lock logic
1004+
const isDeepnoteRelated = await this.isDeepnoteRelatedProcess(pid);
1005+
if (!isDeepnoteRelated) {
1006+
logger.debug(`PID ${pid} is no longer deepnote-related, skipping`);
1007+
pidsToSkip.push({ pid, reason: 'not deepnote-related' });
1008+
continue;
1009+
}
1010+
9991011
// Check if there's a lock file for this PID (only main server processes have lock files)
10001012
const lockData = await this.readLockFile(pid);
10011013

0 commit comments

Comments
 (0)