Skip to content

Enforce Get-Help offline dropback when page or internet is down #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 28, 2018

Conversation

rjmholt
Copy link
Contributor

@rjmholt rjmholt commented Sep 27, 2018

I noticed it was hard to get the offline behaviour in @corbob's awesome addition to fire, so I made a minor edit where we test if the help page is accessible first.

@corbob GitHub won't let me add you as a reviewer, but if you've got time to review please do!

@rjmholt
Copy link
Contributor Author

rjmholt commented Sep 27, 2018

I've ensured that the help API I use to get the URI is available back to PS v3. Any other considerations on that front? Maybe IWR isn't available???

@corbob
Copy link
Contributor

corbob commented Sep 27, 2018

Honestly I designed my addition to only check if it could launch the browser. This will definitely make that better for the scenario where you don't have internet, or the site is down.

I'll try to review this evening or tomorrow morning.

@rjmholt
Copy link
Contributor Author

rjmholt commented Sep 27, 2018

My only concern about my change is that it will be slower -- so will let everyone else decide :)

Copy link
Contributor

@rkeithhill rkeithhill left a comment

Choose a reason for hiding this comment

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

LGTM

@rkeithhill
Copy link
Contributor

Oh, according to the docs, iwr is available in v3 - https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-6


if (string.IsNullOrEmpty(helpParams)) { helpParams = "Get-Help"; }

PSCommand checkHelpPSCommand = new PSCommand()
.AddScript(CheckHelpScript, useLocalScope: true)
.AddArgument(helpParams);

// TODO: Rather than print the help in the console, we should send the string back
Copy link
Contributor

Choose a reason for hiding this comment

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

This actually fits nicely into the changes that PowerShell/vscode-powershell#884 morphed into.

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12

# HEAD means we don't need the content itself back :)
$status = (Invoke-WebRequest -Method Head -Uri $helpUri -ErrorAction Stop).StatusCode
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're overly concerned about speed, we could include -TimeoutSec. However, as per the docs this could still take up to 15 seconds if DNS resolution is slow. If we're in an offline state, is the speed of the timeout that big of an issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would assume in an offline state we'd fail pretty quickly (testing it by unplugging my ethernet cable just then, offline is pretty quick).

But yeah, maybe we should add an explicit timeout. The lower it is the less of a performance hit we take when internet is down in a weird way, but the more likely we will accidentally get offline help for people with slow-but-working internet access.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

5s?

Copy link
Contributor

Choose a reason for hiding this comment

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

5 seconds seems reasonable. I've seen latency as high as 3 - 4 seconds on high speed, but at that point you're better off thinking that you're offline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. Just played with the timeout. Doesn't affect PS Core much either way, but Windows PowerShell seems to much prefer having a 5s timeout

@rjmholt
Copy link
Contributor Author

rjmholt commented Sep 28, 2018

Ok I've verified that the latest change works on my machine (Win 10)

Copy link
Contributor

@corbob corbob left a comment

Choose a reason for hiding this comment

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

Other than the comment about possibly invoking a timeout: LGTM

@rjmholt
Copy link
Contributor Author

rjmholt commented Sep 28, 2018

Wow while testing this I've discovered that you literally cannot start VSCode 1.27.2 without internet connection...

Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

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

LGTM, just missed module qualifying one of the commands.

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12

# HEAD means we don't need the content itself back, just the response header
$status = (Invoke-WebRequest -Method Head -Uri $helpUri -TimeoutSec 5 -ErrorAction Stop).StatusCode
Copy link
Collaborator

Choose a reason for hiding this comment

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

Invoke-WebRequest -> Microsoft.PowerShell.Utility\Invoke-WebRequest

@rjmholt rjmholt merged commit bf7199b into PowerShell:master Sep 28, 2018
@rjmholt rjmholt deleted the show-local-help-console branch December 12, 2018 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants