GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — remoting: Handle DLLImport failure of libpsrpclient by dantraMSFT · Pull Request #5622 · PowerShell/PowerShell

Conversation

@dantraMSFT

@dantraMSFT Dan Travison (dantraMSFT) commented Dec 4, 2017

Copy link
Copy Markdown
Contributor

Issue #4029 exposed two problems when failing to load libpsrpclient.

  • WSManAPIDataCommon.ctor was not identifying the binary that failed DLLImport; hindering diagnosability
  • PrioritySendDataCollection.Clear() would throw a NullReferenceException when called from the finalizer after an error path.

This change addresses both of the above:

  • Guard against null arrays in PrioritySendDataCollection.Clear() - called from finalizer in error paths.

  • Diagnosability: Log the DllNotFoundException in WSManAPIDataCommon ctor and also include it as the internal exception when throwing PSRemotingTransportException.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@dantraMSFT
Dan Travison (dantraMSFT) requested review from Paul Higinbotham (PaulHigin) and Mike Richmond (mirichmo) as code owners December 4, 2017 21:49
@dantraMSFT

Dan Travison (dantraMSFT) commented Dec 5, 2017

Copy link
Copy Markdown
Contributor Author

Mike Richmond (@mirichmo) and Paul Higinbotham (@PaulHigin) will either of you be able to look at this?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anmenaga
Andrew (anmenaga) reviewed Dec 5, 2017
View reviewed changes

@anmenaga Andrew (anmenaga) left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave a comment

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/System.Management.Automation/engine/remoting/fanin/PriorityCollection.cs Outdated

@anmenaga Andrew (anmenaga) Dec 5, 2017

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field is different from array "_syncObjects" only by last letter - it is confusing.
It would be good to either add comment for "_syncObjects" array about what it is; or rename "_syncObject"; or both.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@dantraMSFT Dan Travison (dantraMSFT) Dec 5, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Andrew (@anmenaga): Actually, after reviewing this logic again, _syncObject is insufficient since it only guards Clear(). Additionally, _syncObjects also appears to be fragile; it guards against individual usage of a given element but assumes the elements are valid; which is the actual problem.

My thinking is _syncObjects should be removed and _syncObject used to serialize access to the set instead of individual members.

Thoughts?

Steve Lee (@SteveL-MSFT), Dongbo Wang (@daxian-dbw), Travis Plunk (@TravisEz13) Guys, would you take a look at this class. My inclincation is to remove the individual locks and lock the set.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@anmenaga Andrew (anmenaga) Dec 6, 2017

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dan Travison (@dantraMSFT) I'm all for simplification, but there should be a reason why they decided to go more complex 'individual-sync-object' route in the first place... Maybe something will deadlock with a single syncObject, and parallel "Add"s won't be able to execute for different DataPriorityTypes (not sure how critical this really is).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Jan 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, after reviewing this logic again, _syncObject is insufficient since it only guards Clear().

_dataSyncObjects and _dataToBeSent are used in multiple methods, but it appears that there is an assumption that those methods won't be called until the Fragmentor property is set (where both _dataSyncObjects and _dataToBeSent would be initialized). With this assumption, I think it's fine to directly use _dataSyncObjects and _dataToBeSent in methods other than Clear(). But we probably should add a comment about that assumption.

For Clear(), it's possible to be called before Fragmentor being set (in error path), so it's necessary to check _dataSyncObjects for null beforehand.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@TravisEz13

Travis Plunk (TravisEz13) commented Dec 6, 2017

Copy link
Copy Markdown
Member

also related to issue #5566

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TravisEz13

Travis Plunk (TravisEz13) commented Dec 7, 2017

Copy link
Copy Markdown
Member

LGTM, but I would like Paul Higinbotham (@PaulHigin) to have a look.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TravisEz13

Travis Plunk (TravisEz13) commented Dec 7, 2017

Copy link
Copy Markdown
Member

Andrew (@anmenaga) Do you want to sign off, or did you just comment?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anmenaga

Andrew (anmenaga) commented Dec 7, 2017

Copy link
Copy Markdown

Travis Plunk (@TravisEz13)
The conversation continues about refactoring that Dan proposed; but I think that refactoring (if needs to be done at all) can be done as separate PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anmenaga
Andrew (anmenaga) approved these changes Dec 7, 2017
View reviewed changes

@anmenaga Andrew (anmenaga) left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@TravisEz13 Travis Plunk (TravisEz13) changed the title Handle DLLImport failure of libpsrpclient remoting: Handle DLLImport failure of libpsrpclient Dec 8, 2017
@dantraMSFT Dan Travison (dantraMSFT) assigned Travis Plunk (TravisEz13) Dec 15, 2017
@dantraMSFT

Dan Travison (dantraMSFT) commented Dec 15, 2017

Copy link
Copy Markdown
Contributor Author

Travis Plunk (@TravisEz13) This should be ready to merge.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TravisEz13

Travis Plunk (TravisEz13) commented Dec 15, 2017

Copy link
Copy Markdown
Member

I've been asked to wait for a review by Paul Higinbotham (@PaulHigin) or Dongbo Wang (@daxian-dbw)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

daxian-dbw
Dongbo Wang (daxian-dbw) previously requested changes Jan 2, 2018
View reviewed changes

@daxian-dbw Dongbo Wang (daxian-dbw) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left two comments.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/System.Management.Automation/engine/remoting/fanin/PriorityCollection.cs Outdated

@daxian-dbw Dongbo Wang (daxian-dbw) Jan 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assert should be removed because apparently _dataToBeSent can be null in that error path.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Jan 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind this comment. It's certainly right to assume _dataToBeSent != null when null != _dataSyncObjects 😄

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@dantraMSFT Dan Travison (dantraMSFT) Jan 2, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@dantraMSFT Dan Travison (dantraMSFT) Jan 2, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/System.Management.Automation/engine/remoting/fanin/PriorityCollection.cs Outdated

@daxian-dbw Dongbo Wang (daxian-dbw) Jan 2, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can avoid the sync object _syncObject by the following code:

if (null != _dataSyncObjects)
{
    int promptResponseIndex = (int)DataPriorityType.PromptResponse;
    int defaultIndex = (int)DataPriorityType.Default;

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

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@dantraMSFT Dan Travison (dantraMSFT) Jan 2, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right; I'll make the change.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@dantraMSFT Dan Travison (dantraMSFT) Jan 2, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Dan Travison (dantraMSFT) added 4 commits January 2, 2018 13:07
@dantraMSFT
Issue #4029 exposed two problems when failing to load libpsrpclient. …
996ac53
…WSManAPIDataCommon.ctor was not identifying the binary that failed DLLImport and PrioritySendDataCollection.Clear() would throw a NullReferenceException when called from the finalizer after an error path.

This change addresses both of the above but does not address the DllImport failure.

* Guard against null arrays in PrioritySendDataCollection.Clear() - called from finalizer in error paths.
* Diagnosability: Log DllNotFoundException in WSManAPIDataCommon ctor and also include as the internal exception when throwing PSRemotingTransportException.
@dantraMSFT
Fix coding error in Clear() - setting _dataToBeSent to null too early.
8e69dde
@dantraMSFT
rename _syncObjects to _dataSyncObjects and add comments for clarity
61ab380
@dantraMSFT
Remove _dataSyncObject
4d04401
@dantraMSFT

Dan Travison (dantraMSFT) commented Jan 2, 2018

Copy link
Copy Markdown
Contributor Author

Dongbo Wang (@daxian-dbw) do you have any additional feedback?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dantraMSFT

Dan Travison (dantraMSFT) commented Jan 3, 2018

Copy link
Copy Markdown
Contributor Author

Paul Higinbotham (@PaulHigin), Dongbo Wang (@daxian-dbw), please take a look at this; it's marked as GA. Thanks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT Steve Lee (SteveL-MSFT) added this to the 6.0.0-GA milestone Jan 4, 2018
@daxian-dbw
Dongbo Wang (daxian-dbw) dismissed their stale review January 4, 2018 05:02

My comments have been addressed

daxian-dbw
Dongbo Wang (daxian-dbw) approved these changes Jan 4, 2018
View reviewed changes
@TravisEz13
Travis Plunk (TravisEz13) merged commit 5488131 into PowerShell:master Jan 4, 2018
@dantraMSFT
Dan Travison (dantraMSFT) deleted the dantra/issue4029 branch January 4, 2018 21:36
PaulHigin
Paul Higinbotham (PaulHigin) reviewed Jan 4, 2018
View reviewed changes
Comment thread src/System.Management.Automation/engine/remoting/fanin/PriorityCollection.cs
lock (_syncObjects[(int)DataPriorityType.Default])
{
_dataToBeSent[(int)DataPriorityType.Default].Dispose();
lock (_dataSyncObjects[promptResponseIndex])

@PaulHigin Paul Higinbotham (PaulHigin) Jan 4, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review. I am not familiar with the error path but if _dataToBeSent array can contain null entries then it seems like so can _dataSyncObjects (_dataSyncObjects[promptResponseIndex] == null ?).

It seems like these arrays should be created in the PrioritySendDataCollection constructor...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@dantraMSFT Dan Travison (dantraMSFT) Jan 4, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paul Higinbotham (@PaulHigin): _dataSyncObjects is populated when it is created. The entries are not null if the array is not null.
As far as when it is created, it appears the intent was to create both arrays at the same point. I saw no strong reason to change it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@PaulHigin Paul Higinbotham (PaulHigin) Jan 5, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the _dataSyncObjects array is filled within a loop:

for (int i = 0; i < names.Length; i++)
    {
        _dataToBeSent[i] = new SerializedDataStream(_fragmentor.FragmentSize);
        _dataSyncObjects[i] = new object();
    }

If an exception is thrown within the loop then it is possible an array element is null. Is this not the error path we are worried about?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@dantraMSFT Dan Travison (dantraMSFT) Jan 5, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SerializedDataStream's ctor does not currently throw.

Note that it should (it relies on Dbg.Assert) and I opened an issue for this: #5800

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Travis Plunk (TravisEz13) pushed a commit to TravisEz13/PowerShell that referenced this pull request Jan 5, 2018
@dantraMSFT @TravisEz13
remoting: Handle DLLImport failure of libpsrpclient (PowerShell#5622)
c130f35
Issue PowerShell#4029 exposed two problems when failing to load libpsrpclient.

WSManAPIDataCommon.ctor was not identifying the binary that failed DLLImport; hindering diagnosability
PrioritySendDataCollection.Clear() would throw a NullReferenceException when called from the finalizer after an error path.
This change addresses both of the above:

Guard against null arrays in PrioritySendDataCollection.Clear() - called from finalizer in error paths.

Diagnosability: Log the DllNotFoundException in WSManAPIDataCommon ctor and also include it as the internal exception when throwing PSRemotingTransportException.
@TravisEz13 Travis Plunk (TravisEz13) mentioned this pull request Jan 5, 2018
Merge 6.0.0 ga changes #5793
Merged
Travis Plunk (TravisEz13) pushed a commit that referenced this pull request Jan 5, 2018
@dantraMSFT @TravisEz13
remoting: Handle DLLImport failure of libpsrpclient (#5622)
63b8094
Issue #4029 exposed two problems when failing to load libpsrpclient.

WSManAPIDataCommon.ctor was not identifying the binary that failed DLLImport; hindering diagnosability
PrioritySendDataCollection.Clear() would throw a NullReferenceException when called from the finalizer after an error path.
This change addresses both of the above:

Guard against null arrays in PrioritySendDataCollection.Clear() - called from finalizer in error paths.

Diagnosability: Log the DllNotFoundException in WSManAPIDataCommon ctor and also include it as the internal exception when throwing PSRemotingTransportException.
@daxian-dbw Dongbo Wang (daxian-dbw) mentioned this pull request Jan 8, 2018
NullReferenceException in PrioritySendDataCollection.Clear() #5566
Closed
@iSazonov Ilya (iSazonov) mentioned this pull request Mar 8, 2020
PrioritySendDataCollection.Clear() can throw a null reference exception #5219
Closed
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@dantraMSFT @TravisEz13
remoting: Handle DLLImport failure of libpsrpclient (PowerShell#5622)
05bd4bc
Issue PowerShell#4029 exposed two problems when failing to load libpsrpclient.

WSManAPIDataCommon.ctor was not identifying the binary that failed DLLImport; hindering diagnosability
PrioritySendDataCollection.Clear() would throw a NullReferenceException when called from the finalizer after an error path.
This change addresses both of the above:

Guard against null arrays in PrioritySendDataCollection.Clear() - called from finalizer in error paths.

Diagnosability: Log the DllNotFoundException in WSManAPIDataCommon ctor and also include it as the internal exception when throwing PSRemotingTransportException.
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@dantraMSFT @TravisEz13
remoting: Handle DLLImport failure of libpsrpclient (PowerShell#5622)
27f864a
Issue PowerShell#4029 exposed two problems when failing to load libpsrpclient.

WSManAPIDataCommon.ctor was not identifying the binary that failed DLLImport; hindering diagnosability
PrioritySendDataCollection.Clear() would throw a NullReferenceException when called from the finalizer after an error path.
This change addresses both of the above:

Guard against null arrays in PrioritySendDataCollection.Clear() - called from finalizer in error paths.

Diagnosability: Log the DllNotFoundException in WSManAPIDataCommon ctor and also include it as the internal exception when throwing PSRemotingTransportException.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@daxian-dbw Dongbo Wang (daxian-dbw) daxian-dbw approved these changes
@mirichmo Mike Richmond (mirichmo) Awaiting requested review from mirichmo
+2 more reviewers
@PaulHigin Paul Higinbotham (PaulHigin) PaulHigin left review comments
@anmenaga Andrew (anmenaga) anmenaga approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@TravisEz13 Travis Plunk (TravisEz13)

Labels

None yet

Projects

None yet

Milestone

6.0.0-GA

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@dantraMSFT @TravisEz13 @anmenaga @daxian-dbw @PaulHigin @SteveL-MSFT
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.