Skip to content
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

Fixes: leaking Jobs and broken git prompt #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

burk3
Copy link

@burk3 burk3 commented Mar 9, 2023

I have been using this for my prompt as it is is quite small and is still in pure PowerShell/.Net. I noticed that the Git status part of the prompt wasn't working, so I looked into it a bit and found that the call to Compare-Object was silently failing when it tried comparing the $nulls from the $emptyStatus hash. I swapped the nulls for empty strings and it seems to be working fine now.

While investigating, I also noticed that Get-Job showed many many dead jobs in one of my longer-running shells. Turns out each Register-EngineEvent spins up a new job and they will stick around even if they only needed to live for one event. I stop the leak by keeping track of the last update job and calling Remove-Job on it at the end of it's handler. That seems to just work.

@@ -22,6 +24,7 @@ $Script:OnIdleCallback = {
$isTest ? (&prompt) : [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
}
$pure._state.isPending = $false
Remove-Job $Script:UpdateJob
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we -ErrorAction Ignore this? Just in case the job has already been removed by some other process or race condition?

@nickcox
Copy link
Owner

nickcox commented Mar 9, 2023

This is great, thanks! Just one comment/suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants