-
Notifications
You must be signed in to change notification settings - Fork 510
WIP Enhance Start-EditorServices.ps1 for better logging and fix bugs #1198
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
Conversation
Well, shoot. The Try this. Open VSCode and then a PS1 file, note the lang/debug ports the session is using in the log file. Now try this (substitute in your port #): $port = 29991
$ipAddress = [System.Net.Dns]::GetHostEntryAsync("localhost").Result.AddressList[0];
try { $tcp = New-Object System.Net.Sockets.TcpListener @($ipAddress, $port); $tcp.Start(); $tcp.Stop() } catch [System.Net.Sockets.SocketException] { $_ } Even though that port is in use by an instance of PSES, it shows as available. :-( |
Hmm, if I retrieve the IP address like so, the above code works better: $ipAddress = [System.Net.IPAddress]::Parse("127.0.0.1") This gives an ipv4 address:
It seems that by using
I wonder if we should test both IP address types? |
I noticed that you can do:
but I haven't figured out how to get the ports just yet |
Modify Test-PortAvailability to check each address (ipv4 and ipv6) in AddressList for localhost.
OK, I think this is ready for a serious review. I'd like to get this into 1.6.0 to see if we can get some info to track down why PSES isn't starting up for some folks. I would appreciate someone testing this on macOS. |
Any particular test steps or would you like me to just start/stop vscode a bunch of times? |
The tcp port range is so broad - 10000 to 30000 that it is unlikely that you'll run into ports in use. Could you start one VSCode session - note one of the ports in use (in the log file). Then temporarily hack the $minPortNumber / $maxPortNumber values in the Start-EditorServices.ps1 file (just under params decl) to a range of say 4 around the port number you know to be in use. Then run the extension in the debug host (with log level set to Verbose) and watch the PSIC window as it starts up. I'd like to see that it finds the port known to be in use to be, well, in use. And then attempt another port. Thanks. |
I wonder if these tests are going to fail until a new signature is applied to this script file? |
Hmmm I'm not sure that's the case here. I'm seeing this issue across AppVeyor and Travis: https://travis-ci.org/PowerShell/vscode-powershell/jobs/342931436#L666 |
If that is the case, could we fix the Travis and AppVeyor definitions to be ok with a miss matched signature? If we merge this in, every build will fail (if the mismatched sig is the issue), right? |
I'm not sure. This is the first time I've touched this file but that build failure seems more related to a node/npm issue. Hmm... |
I've restarted them. Let's see what happens. It's also possible that one of our dependencies broke us. If these fail, I want to trigger a build of master which should pass. |
Looks like Travis and AppVeyor had one too many that night and have recovered :) |
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.
Just had a couple of questions.
scripts/Start-EditorServices.ps1
Outdated
$portsInUse[$port] = 1 | ||
|
||
Log "Checking port: $port, attempts remaining $triesRemaining --------------------" | ||
if ($true -eq (Test-PortAvailability -PortNumber $port)) { |
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.
Is the $true -eq ...
needed? I would think Test-PortAvailability is truthy enough.
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.
Or rather, it looks like it returns a boolean, no?
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 I'll put that back the way it was. The reasoning here is if someone tweaks the function and has it output more values the condition should handle that. Turns out that $true -eq '',''
is still true but '','' -eq $true
is false. We want the latter in this case.
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.
That's an interesting gotcha 😅
|
||
try { | ||
if ($isPS5orLater) { | ||
$ipAddress = [System.Net.Dns]::GetHostEntryAsync("localhost").Result.AddressList[0]; | ||
$ipAddresses = [System.Net.Dns]::GetHostEntryAsync("localhost").Result.AddressList |
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.
Did you decide against testing ipv4 via
$ipAddress = [System.Net.IPAddress]::Parse("127.0.0.1")
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.
The above returns both the ipv6 and ipv4 addresses. Note that I'm not limiting the value to the first index and below we iterate the values. IOW the port has to be open on both ipv6 and ipv4 before we will use it.
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.
Ah. I see! Thanks!
Forgive me, as I reviewed this on my phone while waiting for a flight back to Seattle :) |
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 :)
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.
Thanks a lot for doing this, it'll be really helpful in diagnosing startup issues! I'd like to eventually move the port checking code to C# because this script is growing too large, but it's totally worthwhile to improve this for now.
scripts/Start-EditorServices.ps1
Outdated
$minPortNumber = 10000 | ||
$maxPortNumber = 30000 | ||
|
||
if ($LogLevel -ne "Normal") { |
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.
There are "lesser" log levels than Normal (though honestly they're kinda pointless), so maybe you should check for Verbose and Diagnostic specifically? Or maybe just Diagnostic? Can definitely change this in a separate PR so that the release isn't held up.
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.
Doh! I thought that Normal
was the lowest level. I can change it. What do you think? Maybe use Diagnostics
to trigger this - particularly considering this will spew yellow verbose text in the PSIC during startup when Start-EditorServices logging is enabled.
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.
Yeah, I think "Diagnostic" is the right level to enable the logging since we'd only use that level in cases where things have really gone sideways :)
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'll change this tonight. BTW how do we handle the fact that this file had an Authenticode signature which I had to remove because my changes invalidated it?
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.
@tylerl0706 needs to sign the script again when he ships the update. In the past I wasn't checking in the authenticode part, but as time went on it seemed easier to just check it in since the script doesn't change that often between releases.
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.
On the VSCode side, Diagnostics
isn't one of the logging options although I suppose we could add it:
Thoughts? Diagnostics
is available on the PSES side. I'm inclined to leave the script set to trigger on Verbose and consider changing this in a future release. This makes sense from the perspective that right now we're having issues on some machines with startup. Hopefully we get the issues ferreted out and fixed and then we can dial the output back down to happen only with Diagnostics log level.
|
It's not there but I'm working on adding it right now. |
Weird, could have sworn it was there but it's not! |
OK, I've about got this licked. Just need to do a bit of testing. Expect update in 15 mins or so. |
And now we get DIAGNOSTIC log output in the PSES log file.
|
Set Start-EditorServices to log only for Diagnostic log level. Add string enum support for log level so in UserSettings you get a list.
Changes look great to me! |
The first commit, fixes a few bugs with the original Test-PortAvailability function. The second commit. try a different approach to looking for ports in use - see https://stackoverflow.com/questions/570098/in-c-how-to-check-if-a-tcp-port-is-available.
BTW I had to remove the signature to test this and there's no point putting it back because it would be invalid. Seems like we should not commit scripts that are signed but instead, sign them just before publishing.
Here is a sample of
Start-EditorServices.log
contents: