Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ function Restore-PSPester
$Destination = ([IO.Path]::Combine((Split-Path (Get-PSOptions -DefaultToNew).Output), "Modules"))
)

Restore-GitModule -Destination $Destination -Uri 'https://github.com/PowerShell/psl-pester' -Name Pester -CommitSha 'aa243108e7da50a8cf82513b6dd649b653c70b0e'
Restore-GitModule -Destination $Destination -Uri 'https://github.com/PowerShell/psl-pester' -Name Pester -CommitSha '1f546b6aaa0893e215e940a14f57c96f56f7eff1'
}
function Compress-TestContent {
[CmdletBinding()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ internal class PrioritySendDataCollection
// actual data store(s) to store priority based data and its
// corresponding sync objects to provide thread safety.
private SerializedDataStream[] _dataToBeSent;
// array of sync objects, one for each element in _dataToBeSent
private object[] _dataSyncObjects;

// fragmentor used to serialize & fragment objects added to this collection.
private Fragmentor _fragmentor;
private object[] _syncObjects;

// callbacks used if no data is available at any time.
// these callbacks are used to notify when data becomes available under
Expand Down Expand Up @@ -95,11 +97,11 @@ internal Fragmentor Fragmentor
// create serialized streams using fragment size.
string[] names = Enum.GetNames(typeof(DataPriorityType));
_dataToBeSent = new SerializedDataStream[names.Length];
_syncObjects = new object[names.Length];
_dataSyncObjects = new object[names.Length];
for (int i = 0; i < names.Length; i++)
{
_dataToBeSent[i] = new SerializedDataStream(_fragmentor.FragmentSize);
_syncObjects[i] = new object();
_dataSyncObjects[i] = new object();
}
}
}
Expand All @@ -126,7 +128,7 @@ internal void Add<T>(RemoteDataObject<T> data, DataPriorityType priority)
// make sure the only one object is fragmented and added to the collection
// at any give time. This way the order of fragment is maintained
// in the SendDataCollection(s).
lock (_syncObjects[(int)priority])
lock (_dataSyncObjects[(int)priority])
{
_fragmentor.Fragment<T>(data, _dataToBeSent[(int)priority]);
}
Expand Down Expand Up @@ -154,15 +156,33 @@ internal void Add<T>(RemoteDataObject<T> data)
/// </summary>
internal void Clear()
{
Dbg.Assert(null != _dataToBeSent, "Serialized streams are not initialized");
lock (_syncObjects[(int)DataPriorityType.PromptResponse])
/*
NOTE: Error paths during initialization can cause _dataSyncObjects to be null
causing an unhandled exception in finalize and a process crash.
Verify arrays and dataToBeSent objects before referencing.
*/
if (null != _dataSyncObjects && null != _dataToBeSent)
{
_dataToBeSent[(int)DataPriorityType.PromptResponse].Dispose();
}
int promptResponseIndex = (int)DataPriorityType.PromptResponse;
int defaultIndex = (int)DataPriorityType.Default;

lock (_syncObjects[(int)DataPriorityType.Default])
{
_dataToBeSent[(int)DataPriorityType.Default].Dispose();
lock (_dataSyncObjects[promptResponseIndex])
{
if (null != _dataToBeSent[promptResponseIndex])
{
_dataToBeSent[promptResponseIndex].Dispose();
_dataToBeSent[promptResponseIndex] = null;
}
}

lock (_dataSyncObjects[defaultIndex])
{
if (null != _dataToBeSent[defaultIndex])
{
_dataToBeSent[defaultIndex].Dispose();
_dataToBeSent[defaultIndex] = null;
}
}
}
}

Expand Down Expand Up @@ -895,4 +915,4 @@ internal virtual void Dispose(bool isDisposing)
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2602,9 +2602,19 @@ internal WSManAPIDataCommon()
{
ErrorCode = WSManNativeApi.WSManInitialize(WSManNativeApi.WSMAN_FLAG_REQUESTED_API_VERSION_1_1, ref _handle);
}
catch (DllNotFoundException)
{
throw new PSRemotingTransportException(RemotingErrorIdStrings.WSManClientDllNotAvailable);
catch (DllNotFoundException ex)
{
PSEtwLog.LogOperationalError(
PSEventId.TransportError,
PSOpcode.Open,
PSTask.None,
PSKeyword.UseAlwaysOperational,
"WSManAPIDataCommon.ctor",
"WSManInitialize",
ex.HResult.ToString(CultureInfo.InvariantCulture),
ex.Message,
ex.StackTrace);
throw new PSRemotingTransportException(RemotingErrorIdStrings.WSManClientDllNotAvailable, ex);
}

// input / output streams common to all connections
Expand Down