Skip to content

Commit 2345dfc

Browse files
committed
perf: add -nP flag to lsof and cleanup lock files after port-based kills
- Add -nP flag to lsof invocations to avoid slow DNS/service lookups - Clean up lock files after successful process kills in port cleanup logic - Windows: cleanup lock files after both graceful and force kills - Unix: cleanup lock files after graceful kill completes - Uses existing deleteLockFile() helper which safely checks existence - Prevents stale lock files from accumulating after cleanup operations - Improves performance by avoiding unnecessary DNS reverse lookups
1 parent 375326c commit 2345dfc

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/kernels/deepnote/deepnoteServerStarter.node.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,13 +771,19 @@ export class DeepnoteServerStarter implements IDeepnoteServerStarter, IExtension
771771
throwOnStdErr: false
772772
});
773773
logger.debug(`Gracefully killed process ${pid}`);
774+
775+
// Clean up lock file after successful kill
776+
await this.deleteLockFile(pid);
774777
} catch (gracefulError) {
775778
// If graceful kill failed, use /F (force)
776779
logger.debug(`Graceful kill failed for ${pid}, using /F flag...`);
777780
try {
778781
await processService.exec('taskkill', ['/F', '/T', '/PID', pid.toString()], {
779782
throwOnStdErr: false
780783
});
784+
785+
// Clean up lock file after successful force kill
786+
await this.deleteLockFile(pid);
781787
} catch (forceError) {
782788
logger.debug(`Force kill also failed for ${pid}: ${forceError}`);
783789
}
@@ -791,11 +797,15 @@ export class DeepnoteServerStarter implements IDeepnoteServerStarter, IExtension
791797
// Unix-like: try lsof first, fallback to ss
792798
let uniquePids = new Set<number>();
793799

794-
// Try lsof with LISTEN filter
800+
// Try lsof with LISTEN filter and -nP to avoid slow DNS/service lookups
795801
try {
796-
const lsofResult = await processService.exec('lsof', ['-sTCP:LISTEN', '-i', `:${port}`, '-t'], {
797-
throwOnStdErr: false
798-
});
802+
const lsofResult = await processService.exec(
803+
'lsof',
804+
['-sTCP:LISTEN', '-i', `:${port}`, '-t', '-nP'],
805+
{
806+
throwOnStdErr: false
807+
}
808+
);
799809
if (lsofResult.stdout) {
800810
const pids = lsofResult.stdout
801811
.trim()
@@ -849,6 +859,9 @@ export class DeepnoteServerStarter implements IDeepnoteServerStarter, IExtension
849859
`Found orphaned deepnote-related process ${pid} using port ${port}, attempting graceful kill...`
850860
);
851861
await this.killProcessGracefully(pid, processService);
862+
863+
// Clean up lock file after successful kill
864+
await this.deleteLockFile(pid);
852865
} else {
853866
logger.debug(`Deepnote-related process ${pid} on port ${port} has active parent, skipping`);
854867
}

0 commit comments

Comments
 (0)