Skip to content

Commit 6497928

Browse files
committed
🐛 Regression introduced with request deduplication and task mapping
1 parent 3773306 commit 6497928

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

ModuleFast.psm1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,11 @@ function Get-ModuleFastPlan {
477477
[HashSet[ModuleFastInfo]]$modulesToInstall = @{}
478478

479479
# We use this as a fast lookup table for the context of the request
480-
[Dictionary[Task[String], ModuleFastSpec]]$taskSpecMap = @{}
480+
[Dictionary[Task, ModuleFastSpec]]$taskSpecMap = @{}
481481

482482
#We use this to track the tasks that are currently running
483483
#We dont need this to be ConcurrentList because we only manipulate it in the "main" runspace.
484-
[List[Task[String]]]$currentTasks = @()
484+
[List[Task]]$currentTasks = @()
485485

486486
#This is used to track the highest candidate if -Update was specified to force a remote lookup. If the candidate is still the most valid after remote lookup we can skip it without hitting disk to read the manifest again.
487487
[Dictionary[ModuleFastSpec, ModuleFastInfo]]$bestLocalCandidate = @{}
@@ -519,8 +519,11 @@ function Get-ModuleFastPlan {
519519
#For now the content is small but this could be faster if we have another inner loop that WaitAny's on content
520520
#TODO: Perform a HEAD query to see if something has changed
521521

522-
[Task[string]]$completedTask = $currentTasks[$thisTaskIndex]
522+
$completedTask = $currentTasks[$thisTaskIndex]
523523
[ModuleFastSpec]$currentModuleSpec = $taskSpecMap[$completedTask]
524+
if (-not $currentModuleSpec) {
525+
throw 'Failed to find Module Specification for completed task. This is a bug.'
526+
}
524527

525528
Write-Debug "$currentModuleSpec`: Processing Response"
526529
# We use GetAwaiter so we get proper error messages back, as things such as network errors might occur here.
@@ -1340,12 +1343,12 @@ function Get-ModuleInfoAsync {
13401343
$ModuleId = $Name
13411344

13421345
#This call should be cached by httpclient after first attempt to speed up future calls
1343-
Write-Debug ('{0}fetch registration index from {1}' -f ($ModuleId ? "$ModuleId`: " : ''), $Endpoint)
13441346
$endpointTask = $SCRIPT:RequestCache[$Endpoint]
13451347

13461348
if ($endpointTask) {
13471349
Write-Debug "REQUEST CACHE HIT for Registration Index $Endpoint"
13481350
} else {
1351+
Write-Debug ('{0}fetch registration index from {1}' -f ($ModuleId ? "$ModuleId`: " : ''), $Endpoint)
13491352
$endpointTask = $HttpClient.GetStringAsync($Endpoint, $CancellationToken)
13501353
$SCRIPT:RequestCache[$Endpoint] = $endpointTask
13511354
}
@@ -1368,6 +1371,8 @@ function Get-ModuleInfoAsync {
13681371

13691372
if ($requestTask) {
13701373
Write-Debug "REQUEST CACHE HIT for $Uri"
1374+
#HACK: We need the task to be a unique reference for the context mapping that occurs later on, so this is an easy if obscure way to "clone" the task using PowerShell.
1375+
$requestTask = [Task]::WhenAll($requestTask)
13711376
} else {
13721377
Write-Debug ('{0}fetch info from {1}' -f ($ModuleId ? "$ModuleId`: " : ''), $uri)
13731378
$requestTask = $HttpClient.GetStringAsync($uri, $CancellationToken)

0 commit comments

Comments
 (0)