-
Notifications
You must be signed in to change notification settings - Fork 11
fix ghost ps process instances #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,20 @@ function Start-McpServer { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Write-Log -LogEntry @{ Level = 'Info'; Message = "Starting MCP Server" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while ($true) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Check if parent process is still running otherwise exit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $parentProcess = Get-Process -Id $parentProcessId -ErrorAction Stop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($null -eq $parentProcess) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Write-Log -LogEntry @{ Level = 'Info'; Message = "Parent process has exited. Shutting down MCP server..." } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+29
to
+32
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($null -eq $parentProcess) { | |
| Write-Log -LogEntry @{ Level = 'Info'; Message = "Parent process has exited. Shutting down MCP server..." } | |
| exit | |
| } |
Copilot
AI
Dec 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking if the parent process is running on every iteration of the while loop could impact performance, especially when processing many requests. Consider checking the parent process less frequently, such as every N iterations or using a timer-based approach, to reduce the overhead while still catching orphaned processes in a reasonable timeframe.
| while ($true) { | |
| # Check if parent process is still running otherwise exit | |
| try { | |
| $parentProcess = Get-Process -Id $parentProcessId -ErrorAction Stop | |
| if ($null -eq $parentProcess) { | |
| Write-Log -LogEntry @{ Level = 'Info'; Message = "Parent process has exited. Shutting down MCP server..." } | |
| exit | |
| } | |
| } | |
| catch { | |
| Write-Log -LogEntry @{ Level = 'Info'; Message = "Parent process not found. Shutting down MCP server..." } | |
| exit | |
| } | |
| # Control how often we check whether the parent process is still running | |
| $parentCheckInterval = 100 | |
| $iterationCount = 0 | |
| while ($true) { | |
| $iterationCount++ | |
| # Check if parent process is still running otherwise exit (only every N iterations) | |
| if ($iterationCount % $parentCheckInterval -eq 0) { | |
| try { | |
| $parentProcess = Get-Process -Id $parentProcessId -ErrorAction Stop | |
| if ($null -eq $parentProcess) { | |
| Write-Log -LogEntry @{ Level = 'Info'; Message = "Parent process has exited. Shutting down MCP server..." } | |
| exit | |
| } | |
| } | |
| catch { | |
| Write-Log -LogEntry @{ Level = 'Info'; Message = "Parent process not found. Shutting down MCP server..." } | |
| exit | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable
$parentProcessIdis not defined anywhere in the function. It's not included in the function parameters, and there's no evidence of it being set in the module scope. This code will fail at runtime because PowerShell will not be able to resolve this variable. Consider adding$parentProcessIdas a parameter to the function, or use the automatic variable$PIDwith a mechanism to track the parent process ID.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops :) Sorry, seems I forgot to insert from the beginning 🤦♂️ Will fix it now