Skip to content

Commit 5ce9bbb

Browse files
committed
remove debug statements in concurrency
1 parent 820b411 commit 5ce9bbb

3 files changed

Lines changed: 114 additions & 98 deletions

File tree

src/code/InstallHelper.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ private ConcurrentDictionary<string, Hashtable> InstallParentAndDependencyPackag
924924
// TODO: figure out a good threshold and parallel count
925925
int processorCount = Environment.ProcessorCount;
926926
_cmdletPassedIn.WriteDebug($"parentAndDeps.Count is {parentAndDeps.Count}, processor count is: {processorCount}");
927-
if (parentAndDeps.Count > processorCount)
927+
if (parentAndDeps.Count > 0)
928928
{
929929
_cmdletPassedIn.WriteDebug($"parentAndDeps.Count is greater than processor count");
930930
// Set the maximum degree of parallelism to 32? (Invoke-Command has default of 32, that's where we got this number from)
@@ -937,12 +937,34 @@ private ConcurrentDictionary<string, Hashtable> InstallParentAndDependencyPackag
937937
var depPkgVersion = depPkg.Version.ToString();
938938

939939
Stream responseStream = currentServer.InstallPackage(depPkgName, depPkgVersion, true, out ErrorRecord installNameErrRecord);
940+
941+
var nullresp = false;
942+
if (responseStream == null)
943+
{
944+
nullresp = true;
945+
}
946+
947+
// if (currentServer.Repository.ApiVersion == PSRepositoryInfo.APIVersion.V2)
948+
// {
949+
// // See if the network call we're making is already cached, if not, call FindNameAsync() and cache results
950+
// string key = $"{dep.Name}|{dep.VersionRange.MaxVersion.ToString()}|{_type}";
951+
// response = _cachedNetworkCalls.GetOrAdd(key, _ => currentServer.FindVersionAsync(dep.Name, dep.VersionRange.MaxVersion.ToString(), _type));
952+
953+
// responses = response.GetAwaiter().GetResult();
954+
// }
955+
// else
956+
// {
957+
// responses = currentServer.FindVersion(dep.Name, dep.VersionRange.MaxVersion.ToString(), _type, out errRecord);
958+
// }
959+
960+
961+
940962
//_cmdletPassedIn.WriteDebug("In BeginInstallPackage 938");
941963

942964
if (installNameErrRecord != null)
943965
{
944966
// _cmdletPassedIn.WriteDebug("In BeginInstallPackage 942");
945-
errors.Add(installNameErrRecord);
967+
//errors.Add(installNameErrRecord);
946968
}
947969
// _cmdletPassedIn.WriteDebug("In BeginInstallPackage 945");
948970
ErrorRecord tempSaveErrRecord = null, tempInstallErrRecord = null;
@@ -951,7 +973,7 @@ private ConcurrentDictionary<string, Hashtable> InstallParentAndDependencyPackag
951973

952974
if (!installedToTempPathSuccessfully)
953975
{
954-
errors.Add(tempSaveErrRecord ?? tempInstallErrRecord);
976+
//errors.Add(tempSaveErrRecord ?? tempInstallErrRecord);
955977
}
956978
});
957979

@@ -965,7 +987,7 @@ private ConcurrentDictionary<string, Hashtable> InstallParentAndDependencyPackag
965987

966988
return packagesHash;
967989
}
968-
if (string.IsNullOrEmpty(warning))
990+
if (!string.IsNullOrEmpty(warning))
969991
{
970992
_cmdletPassedIn.WriteWarning(warning);
971993
}
@@ -1081,6 +1103,10 @@ private bool TryInstallToTempPath(
10811103
{
10821104
var pathToFile = Path.Combine(tempInstallPath, $"{pkgName}.{normalizedPkgVersion}.zip");
10831105
using var fs = File.Create(pathToFile);
1106+
if (responseStream == null)
1107+
{
1108+
throw new InvalidOperationException("responseStream is null");
1109+
}
10841110
responseStream.Seek(0, System.IO.SeekOrigin.Begin);
10851111
responseStream.CopyTo(fs);
10861112
fs.Close();

src/code/Utils.cs

Lines changed: 45 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,6 @@ public static bool TryReadRequiredResourceFile(
13331333
out resourceInfo,
13341334
out error);
13351335
}
1336-
13371336
private static bool TryReadPSDataFile(
13381337
string filePath,
13391338
string[] allowedVariables,
@@ -1354,84 +1353,70 @@ private static bool TryReadPSDataFile(
13541353

13551354
// Parallel.ForEach calls into this method.
13561355
// Each thread needs its own runspace created to provide a separate environment for operations to run independently.
1357-
// The runspace must be disposed when done and DefaultRunspace must be set/restored per-thread
1358-
// to prevent cross-contamination when thread-pool threads are reused across tests.
13591356
Runspace runspace = RunspaceFactory.CreateRunspace();
13601357
runspace.Open();
13611358
runspace.SessionStateProxy.LanguageMode = PSLanguageMode.ConstrainedLanguage;
13621359

1363-
// Save and set the default runspace for the current thread to prevent
1364-
// stale DefaultRunspace from a prior operation on this reused thread-pool thread.
1365-
Runspace previousDefaultRunspace = Runspace.DefaultRunspace;
1366-
try
1360+
// Set the created runspace as the default for the current thread
1361+
//Runspace.DefaultRunspace = runspace;
1362+
1363+
using (System.Management.Automation.PowerShell pwsh = System.Management.Automation.PowerShell.Create())
13671364
{
1368-
Runspace.DefaultRunspace = runspace;
1365+
pwsh.Runspace = runspace;
13691366

1370-
using (System.Management.Automation.PowerShell pwsh = System.Management.Automation.PowerShell.Create())
1371-
{
1372-
pwsh.Runspace = runspace;
1367+
var cmd = new Command(
1368+
command: contents,
1369+
isScript: true,
1370+
useLocalScope: true);
1371+
cmd.MergeMyResults(
1372+
myResult: PipelineResultTypes.Error | PipelineResultTypes.Warning | PipelineResultTypes.Verbose | PipelineResultTypes.Debug | PipelineResultTypes.Information,
1373+
toResult: PipelineResultTypes.Output);
1374+
pwsh.Commands.AddCommand(cmd);
13731375

1374-
var cmd = new Command(
1375-
command: contents,
1376-
isScript: true,
1377-
useLocalScope: true);
1378-
cmd.MergeMyResults(
1379-
myResult: PipelineResultTypes.Error | PipelineResultTypes.Warning | PipelineResultTypes.Verbose | PipelineResultTypes.Debug | PipelineResultTypes.Information,
1380-
toResult: PipelineResultTypes.Output);
1381-
pwsh.Commands.AddCommand(cmd);
13821376

1383-
try
1384-
{
1385-
// Invoke the pipeline and retrieve the results
1386-
var results = pwsh.Invoke();
1377+
try
1378+
{
1379+
// Invoke the pipeline and retrieve the results
1380+
var results = pwsh.Invoke();
13871381

1388-
if (results[0] is PSObject pwshObj)
1382+
if (results[0] is PSObject pwshObj)
1383+
{
1384+
switch (pwshObj.BaseObject)
13891385
{
1390-
switch (pwshObj.BaseObject)
1391-
{
1392-
case ErrorRecord err:
1393-
//_cmdletPassedIn.WriteError(error);
1394-
break;
1386+
case ErrorRecord err:
1387+
//_cmdletPassedIn.WriteError(error);
1388+
break;
13951389

1396-
case WarningRecord warning:
1397-
//cmdlet.WriteWarning(warning.Message);
1398-
break;
1390+
case WarningRecord warning:
1391+
//cmdlet.WriteWarning(warning.Message);
1392+
break;
13991393

1400-
case VerboseRecord verbose:
1401-
//cmdlet.WriteVerbose(verbose.Message);
1402-
break;
1394+
case VerboseRecord verbose:
1395+
//cmdlet.WriteVerbose(verbose.Message);
1396+
break;
14031397

1404-
case DebugRecord debug:
1405-
//cmdlet.WriteDebug(debug.Message);
1406-
break;
1398+
case DebugRecord debug:
1399+
//cmdlet.WriteDebug(debug.Message);
1400+
break;
14071401

1408-
case InformationRecord info:
1409-
//cmdlet.WriteInformation(info);
1410-
break;
1402+
case InformationRecord info:
1403+
//cmdlet.WriteInformation(info);
1404+
break;
14111405

1412-
case Hashtable result:
1413-
dataFileInfo = result;
1414-
return true;
1415-
}
1406+
case Hashtable result:
1407+
dataFileInfo = result;
1408+
return true;
14161409
}
14171410
}
1418-
catch (Exception ex)
1419-
{
1420-
error = ex;
1421-
}
14221411
}
1423-
// Return false to indicate "we couldn't parse a valid Hashtable from this .psd1 file."
1424-
// The only success path is the 'case Hashtable result' branch above which does return true.
1425-
return false;
1426-
}
1427-
finally
1428-
{
1429-
// Always restore the previous default runspace and close/dispose
1430-
// the per-thread runspace, even on success (return true) or exception paths.
1431-
Runspace.DefaultRunspace = previousDefaultRunspace;
1432-
runspace.Close();
1433-
runspace.Dispose();
1412+
catch (Exception ex)
1413+
{
1414+
error = ex;
1415+
}
14341416
}
1417+
runspace.Close();
1418+
1419+
return false;
14351420
}
14361421
catch (Exception ex)
14371422
{

0 commit comments

Comments
 (0)