Skip to content

Conversation

CarloToso
Copy link
Contributor

@CarloToso CarloToso commented Mar 16, 2023

PR Summary

Replaces #18995 after the changes in #19249

  • Replaces HttpClientHanlder with SocketsHttpHandler
  • Adds support for UnixSockets
  • Now passes all the tests

Syntax:
curl --unix-socket /var/run/docker.sock http://v1.40/images/json
Invoke-WebRequest -Uri "http://v1.40/images/json/" -UnixSocket "/var/run/docker.sock"

TODO:

  • Add specific tests (Help Wanted) DONE
  • Add documentation DONE

PR Context

fix #12060
fix #8314

PR Checklist

@CarloToso
Copy link
Contributor Author

Unrelated test error

Copy link
Member

@SteveL-MSFT SteveL-MSFT left a comment

Choose a reason for hiding this comment

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

LGTM

@ghost ghost added the Review - Needed The PR is being reviewed label Apr 4, 2023
@ghost
Copy link

ghost commented Apr 4, 2023

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@xtqqczze
Copy link
Contributor

I wonder whether we should handle Socket.OSSupportsUnixDomainSockets is false during argument validation, or later in CreateHttpClient. In any case, would it be better for the error to have ErrorCategory.NotImplemented?

get => _unixSocket;
set
{
if (Socket.OSSupportsUnixDomainSockets is true)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to create UnixSocket if Socket.OSSupportsUnixDomainSockets is false? I guess no. So it makes no sense to add the check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iSazonov unfortunately I can't check at the moment, could you test what happens if Socket.OSSupportsUnixDomainSockets is false?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor

@xtqqczze xtqqczze Apr 12, 2023

Choose a reason for hiding this comment

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

Actually System.Net.Sockets.Socket..ctor(AddressFamily, SocketType, ProtocolType) will throw a SocketException with the message "An address incompatible with the requested protocol was used":

https://github.com/dotnet/runtime/blob/2c8cb129ed084e374f06eaa29f21e9ab0b9e8066/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs#L81-L100

Copy link
Contributor

@xtqqczze xtqqczze Apr 12, 2023

Choose a reason for hiding this comment

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

Copy link
Contributor

@xtqqczze xtqqczze Apr 12, 2023

Choose a reason for hiding this comment

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

Is it possible to create UnixSocket if Socket.OSSupportsUnixDomainSockets is false? I guess no. So it makes no sense to add the check.

We probably want to perform the check so that we can create the appropriate ErrorRecord with a more informative message, i.e.:

if (!Socket.OSSupportsUnixDomainSockets)
  ThrowTerminatingError(GetUnixDomainSocketNotSupportedError())
```</strike>

Copy link
Contributor

@xtqqczze xtqqczze Apr 12, 2023

Choose a reason for hiding this comment

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

That being said, the error handling of System.Net.Sockets.SocketPal.CreateSocket could be improved.

@ghost ghost added the Review - Needed The PR is being reviewed label Jun 5, 2023
@ghost
Copy link

ghost commented Jun 5, 2023

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@ghost ghost added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Review - Needed The PR is being reviewed labels Jul 10, 2023
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jul 10, 2023
@CarloToso
Copy link
Contributor Author

@SteveL-MSFT
It was handled in the following commits following @xtqqczze 's suggestions:
d9ec5c4; bd5c4d6; f7ec7e8; 2b9a2b9
and removed as asked by @iSazonov (#19343 (comment))
e7090f3

@xtqqczze
Copy link
Contributor

@SteveL-MSFT It was handled in the following commits following @xtqqczze 's suggestions: d9ec5c4; bd5c4d6; f7ec7e8; 2b9a2b9 and removed as asked by @iSazonov (#19343 (comment)) e7090f3

I agree with @iSazonov, error handling is not required, see #19343 (comment).

@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Jul 18, 2023
@microsoft-github-policy-service
Copy link
Contributor

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

1 similar comment
@microsoft-github-policy-service
Copy link
Contributor

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

Copy link
Member

@SteveL-MSFT SteveL-MSFT left a comment

Choose a reason for hiding this comment

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

LGTM

@daxian-dbw
Copy link
Member

Context
#12060 and #8314

Does this PR fix those 2 issues? Can they be closed after merging this PR?

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Review - Needed The PR is being reviewed label Jul 24, 2023
@CarloToso
Copy link
Contributor Author

Context
#12060 and #8314

Does this PR fix those 2 issues? Can they be closed after merging this PR?

Yes

@daxian-dbw
Copy link
Member

@CarloToso The markdown spelling check failed. Please fix the markdown spelling issues.

@pull-request-quantifier-deprecated

This PR has 176 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Medium
Size       : +164 -12
Percentile : 55.2%

Total files changed: 10

Change summary by file extension:
.spelling : +1 -0
.psm1 : +77 -1
.cs : +34 -11
.ps1 : +13 -0
.md : +12 -0
.psd1 : +16 -0
.csproj : +11 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@daxian-dbw daxian-dbw merged commit e8ce6a5 into PowerShell:master Jul 24, 2023
@daxian-dbw daxian-dbw added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jul 24, 2023
@CarloToso CarloToso deleted the WebCmdlets-UnixSockets2 branch July 25, 2023 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log CommunityDay-Large A large PR that the PS team has identified to prioritize to review Documentation Needed in this repo Documentation is needed in this repo Medium Needs-Triage The issue is new and needs to be triaged by a work group. PowerShell-Docs needed The PR was reviewed and a PowerShell Docs update is needed WG-Cmdlets general cmdlet issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invoke-WebRequest and Invoke-RestMethod should support Unix Domain Sockets Support using sockaddr_un scheme with Invoke-RestMethod.
7 participants