Invoke-Parallel - Its runspace pool on $Host hides the warnings and progress of the caller from API hosts
Los mantenedores suelen responder en 2 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- powershell
- Área
- backend
Línea de trabajo
Start with private/functions/flowcontrol/Invoke-Parallel.ps1, especially the runspace pool creation around line 450 and the EndInvoke handling around lines 293-298. Read the linked #10789 fix and compare options B and C, since the issue says a maintainer decision is needed before coding. Reproduce the stream behavior with a PowerShell API host and an isolated runspace; done means the chosen behavior preserves caller warnings and verbose messages and has coverage for a real caller such as Update-ServiceStatus.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
@potatoqualitee this one needs your decision before anyone writes code.
The problem
private/functions/flowcontrol/Invoke-Parallel.ps1 line 450 creates its runspace pool on the host of the caller:
$runspacepool = [runspacefactory]::CreateRunspacePool(1, $Throttle, $sessionstate, $Host)
This is the defect that #10789 fixes in Read-DbaBackupHeader and Start-/Stop-DbaDbEncryption (#10776, section 1). Once a thread of such a pool has run, the warnings, verbose messages and progress records of the calling pipeline no longer reach the streams of a host created through the PowerShell API: automation hosts, SDK hosts, notebooks, and our own tests that run a command in a runspace of its own. Output and errors still arrive. In a console nobody notices, because the records go to the console UI. The repro in #10776 shows it with ten lines and no dbatools; it behaves the same on 5.1 and 7.6.
The callers of Invoke-Parallel:
| Caller | When it runs in parallel |
|---|---|
| Install-DbaInstance (line 913) | two or more computers |
| Update-DbaInstance (line 718) | two or more computers |
| Start-/Stop-/Restart-DbaService through private Update-ServiceStatus (line 278) | always |
| Invoke-DbaPfRelog (line 456) | -Multithread |
Through an API host this loses, for example, the progress bar of Invoke-Parallel itself and the warnings of Install-DbaInstance after the installations. Update-ServiceStatus is hit hardest: its threads return the results of the service actions, and the caller writes the warning for every service that failed ("($target) $($_.Service.Message)", line 281). So a script that restarts services through an API host never sees which ones failed.
Why this one is not a one-line fix
In #10789 the threads write nothing but output and errors, so the pool simply lost $Host there. Here some threads write more. Install-DbaInstance and Update-DbaInstance run Invoke-DbaAdvancedInstall and Invoke-DbaAdvancedUpdate in them, which draw progress bars and warn through Stop-Function, and so can the relog script of Invoke-DbaPfRelog. Today a console user sees those warnings and bars live, because they go through $Host. The service threads of Update-ServiceStatus do not import dbatools and only return objects, so for them dropping $Host loses nothing.
Invoke-Parallel forwards only the errors of a finished thread (lines 293-298, Write-Error -ErrorRecord). Its warnings, verbose messages, information and progress stay in the thread's streams. A lab probe in October (5.1 and 7.6, reading the screen buffer of a real console) showed:
- Pool on
$Host: the console shows the warnings, verbose messages andWrite-Hostof the threads, and the API caller loses its later warnings and verbose messages. - Pool without a host (
CreateRunspacePool($sessionstate)plusSetMaxRunspaces($Throttle); there is no overload with minimum, maximum and session state but no host): the console shows nothing of the threads, and the caller keeps all its streams. - In both variants the thread's own
Streams.Warning,Streams.VerboseandStreams.Progressare filled, so they can be forwarded.
Options
A. Keep $Host. Nothing changes for console users. API hosts keep losing the caller's warnings, verbose messages and progress after the first thread ran.
B. No host, and forward the thread's streams when the thread ends. Next to the errors, Invoke-Parallel writes the thread's warnings, verbose messages and information records in the caller's pipeline right after EndInvoke. All messages arrive, in every host. But warnings come when the computer is done instead of live, and the progress bars of the threads are no longer shown. The bar of Invoke-Parallel itself ("Installing SQL Server ... on n computers") stays. Small change, in one place.
C. No host, and forward while the threads run. Invoke-Parallel already polls its threads every SleepTimer milliseconds. On each round it would read the records each running thread added since the last round and write them in the caller's pipeline: warnings with Write-Warning, progress with Write-Progress. This is nearly live in every host. But it is more code, and the progress Ids need a mapping per thread: the threads draw with Write-ProgressHelper and Id 0 (or their own), so two threads would overwrite each other's bars and the bar of Invoke-Parallel. That is the Id ownership question of #10548.
My recommendation is B now. It closes the gap for API hosts, and nothing is lost except the live bars of the threads. C can follow with #10548, once bar ownership is settled. If the live bars of parallel installs matter to you, C right away.
Testing
As in #10789: run the command through [powershell]::Create() in a runspace of its own, and check that a warning written after the threads have run reaches Streams.Warning. Update-ServiceStatus is the cheapest real caller, because it needs no installation media: a service action that fails makes the caller warn after the threads ran. With B or C, also check that a warning written inside a thread arrives, for example with Invoke-DbaPfRelog -Multithread and a file it cannot read.
This text was created by Claude and reviewed by Andreas Jordan.
- Lenguaje dominante
- PowerShell
- Estrellas
- 2.9k
- Forks
- 869
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 38
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de dataplat/dbatools
-
bugs life triage required
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 2 días
-
bugs life triage required
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 2 días
-
Invoke-DbaDbPiiScan - Fix broken PII patterns, add Nordic known names, and proposals for metadata-only scan and native classificationPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
Los mantenedores suelen responder en 2 días
-
bugs life triage required
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
dataplat/dbatools#10860 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
bugs life Chrissy needed
Dificultad 3/5 Medio día Aptitud para principiantes 38/100
Los mantenedores suelen responder en 2 días
Todos los issues de dataplat/dbatools
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
fix(core): \.pluck() returns values in key insertion order instead of requested argument orderPosiblemente ocupada @ManyaS-Git la tomó hace 1 día. Abiertostatus:in-linear
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
n8n-io/n8n#45027 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[BUG]: chunkSource protocol stripping truncates URLs or reads an inner schemePosiblemente ocupada @Bensonbenyi la tomó hoy. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Mintplex-Labs/anything-llm#7338 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
lidofinance/validator-ejector#228 ·
Los mantenedores suelen responder en 1 día