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

Inconsistent pipeline thread stack size #17407

Open
5 tasks done
fflaten opened this issue May 22, 2022 · 6 comments
Open
5 tasks done

Inconsistent pipeline thread stack size #17407

fflaten opened this issue May 22, 2022 · 6 comments
Labels
Issue-Enhancement the issue is more of a feature request than a bug WG-Remoting PSRP issues with any transport layer

Comments

@fflaten
Copy link
Contributor

fflaten commented May 22, 2022

Prerequisites

Steps to reproduce

Example 1:

  1. Run Start-Job { function recurse([int]$i) { $i; recurse ($i+1) }; recurse 0 } | Receive-Job -Wait
  2. Run function recurse([int]$i) { $i; recurse ($i+1) }; recurse 0

Example 2 on Windows:
Run the following block directly in Powershell session and then inside a job

$signature = @'
[DllImport("kernel32.dll")]
public static extern void GetCurrentThreadStackLimits(out uint lowLimit, out uint highLimit);
'@

$type = Add-Type -MemberDefinition $signature -Name Win32Pinvoke -PassThru

$low, $high = 0, 0
$type::GetCurrentThreadStackLimits([ref]$low, [ref]$high)
($high - $low)/1MB

Expected behavior

Example 1: Recurse-loop fails on somewhat similar depth.
Example 2: Same/similar stack size reported

Actual behavior

Example 1: Job stops on 1215. Local pipeline (step 2) stops/freezes on 9000+
Example 2: Job reports 1,5MB. Local pipeline reports 9,5MB stack size. 

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.3
PSEdition                      Core
GitCommitId                    7.2.3
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

@fflaten fflaten added the Needs-Triage The issue is new and needs to be triaged by a work group. label May 22, 2022
@fflaten
Copy link
Contributor Author

fflaten commented May 22, 2022

#6224 brought the 10MB default from Windows PowerShell for local pipeline into PowerShell. Foreach-Object -Parallel also use the 10MB DefaultPipelineStackSize

Any reason why the same limit isn't used for jobs and remote sessions?

@iSazonov
Copy link
Collaborator

I think it makes sense to have the same limit.

/cc @PaulHigin

@daxian-dbw daxian-dbw added the WG-Remoting PSRP issues with any transport layer label May 27, 2022
@PaulHigin
Copy link
Contributor

@WG-Remoting

Remote execution of commands and script is more complex than with the local pipeline case. By default the remoting endpoint will run commands/script on the same thread the remoting message is processed on, to save the overhead of generating extra threads. In the Start-Job case, these are .Net threadpool threads and you cannot change the stack size on them AFAIK.

There is a mechanism to change this default behavior and specify a PSThreadOptions.UseNewThread which will cause the remoting endpoint to execute the command/script in a new PS pipeline thread, which will automatically get the 10MB stack size. However, this is not currently exposed through Start-Job, but is something that could be added.

@PaulHigin PaulHigin added Issue-Enhancement the issue is more of a feature request than a bug and removed Needs-Triage The issue is new and needs to be triaged by a work group. labels Jun 27, 2022
@microsoft-github-policy-service microsoft-github-policy-service bot added the Resolution-No Activity Issue has had no activity for 6 months or more label Nov 15, 2023
@fflaten
Copy link
Contributor Author

fflaten commented Nov 30, 2023

I still believe this is worth a fix to provide a consistent environment for users regardless of how they invoke their code.

@fflaten
Copy link
Contributor Author

fflaten commented May 13, 2024

@iSazonov Could we please reopen this? Still relevant and I don't like duplicating issues 🙂

@fflaten
Copy link
Contributor Author

fflaten commented May 13, 2024

By default the remoting endpoint will run commands/script on the same thread the remoting message is processed on, to save the overhead of generating extra threads.

@PaulHigin Thanks for the previous answer. Adding an option to Start-Job would definitely help.

Could you elaborate a little about the overhead with using an extra thread for remote sessions? Is it a <1sec delayed session start? Higher memory usage?

@iSazonov iSazonov reopened this May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement the issue is more of a feature request than a bug WG-Remoting PSRP issues with any transport layer
Projects
None yet
Development

No branches or pull requests

4 participants