-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Start-Process fails with EnvironmentBlockTooLong
error
#14110
Comments
@hbuckle Do you want to pull PR? |
Absolutely, if it's fine to remove the limit I'll create a PR |
I believe we can remove the limit because Windows XP is out of support. Since the issue is related to Azure Pipelines I'd ask MSFT team to include the fix in servicing release 7.1.1. |
IIRC there's a limit of 32767 (0xFFFF as a signed Int16) on environment blocks defined by the user https://docs.microsoft.com/en-us/windows/win32/procthread/environment-variables on Windows. Removing this limit could potentially cause undefined errors.
|
@jborean93 - from that documentation
So the limit seems to be on the size of individual variables, not on the size of the block? |
That's true, It does also say
But it's definitely more on the side of it should work and it's up to the user of the environment block to handle it properly and not something PowerShell should limit. |
This issue appeared in PowerShell 7.1.0 as part of #10830 And appeared in Azure Pipelines for me today as the agent got updated to use PowerShell 7.1.0 Until the linked PR #14111 is in a workaround for some scenarios where you don't need to inherit environment variables from the process (or deployment pipeline in the case of Azure Pipelines) is to use This fixed my issue trying to run an app inside of Azure Pipelines for now. |
@MattJeanes - I don't think it was introduced in 7.1, I'm assuming it has been there since the days of Windows XP. I wonder if something changed in Azure Pipelines that meant they started creating more environment variables |
The behaviour of PowerShell was changed to call You can see that change here: https://github.com/PowerShell/PowerShell/pull/10830/files#diff-a87e81856755f9e2a0f6002cf90c4cc3d0a4d1e81394bee7ac61543f71138b71R2464
|
Yes, this is a side effect from old code. The implementation was changed as first step to open a way for supporting new features (like adding new env vars on the fly by new parameter (I already forget approved name :-) ) and language feature like bash style |
I have run into a situation where I needed to pass in environment variables to a process, so to work around the issue I essentially temporarily move a bunch of environment variables to a variable, run the processes and then move them back. Here are the scripts to do it, they remove all function Clear-EnvironmentVariablesTemporary {
# TEMPORARY: https://github.com/PowerShell/PowerShell/issues/14110
$global:ClearedEnvironmentVariables = (Get-Item "env:").ForEach({
if ($_.Key.StartsWith("RELEASE_")) {
return $_
}
})
$global:ClearedEnvironmentVariables | ForEach-Object { Remove-Item (Join-Path "env:" $_.Key) }
Write-Host "Cleared $($global:ClearedEnvironmentVariables.Count) environment variables"
}
function Restore-EnvironmentVariablesTemporary {
# TEMPORARY: https://github.com/PowerShell/PowerShell/issues/14110
if ($global:ClearedEnvironmentVariables) {
$global:ClearedEnvironmentVariables | ForEach-Object { Set-Item (Join-Path "env:" $_.Key) -Value $_.Value }
}
else {
Write-Warning "No cleared environment variables saved, cannot restore"
}
Write-Host "Restored $($global:ClearedEnvironmentVariables.Count) environment variables"
$global:ClearedEnvironmentVariables = $null
} |
🎉This issue was addressed in #14111, which has now been successfully released as Handy links: |
🎉This issue was addressed in #14111, which has now been successfully released as Handy links: |
It seems that Start-Process has a hardcoded limit for the environment block, which I am hitting when running in Azure Pipelines (which sets lots of environment variables)
According to the documentation this limit only existed for Windows XP, is there any reason for it to remain?
Steps to reproduce
Expected behavior
Process is executed
Actual behavior
The text was updated successfully, but these errors were encountered: