-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Make Test-Connection always use the default synchronization context for sending ping requests #11517
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
src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Outdated
Show resolved
Hide resolved
180fd27 to
0bc2838
Compare
src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Show resolved
Hide resolved
vexx32
left a comment
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.
Seems sound to me. This looks a lot nicer!
Thanks for fixing this! 😊 💖
test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1
Outdated
Show resolved
Hide resolved
|
@daxian-dbw does this allow Ctrl+C to cancel the ping? The documentation for Downloaded the build artifact, and it seems to cancel, but the task doesn't return until the predefined timeout either way... though it does stop. Weird. So I guess it sort of does, but it won't cause the task to return right away. Odd. I think it was already doing that before this change, though, so it must be something that the API is doing internally, a shared code path somewhere, most likely. |
|
@vexx32 |
SeeminglyScience
left a comment
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, nice catch on the inner exception 🙂
One comment
src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Outdated
Show resolved
Hide resolved
Is it EAP behavior? I ask because SendAsync() creates an async task with ConfigureAwait(false) Also I should point may be related #11420 (comment) .Net Core uses ConfigureAwait(false) everywhere. If there is something that blocking current thread I guess it is either Core bug or by-design in EAP. |
|
@iSazonov yeah traceroutes take a while even on Windows, but are especially bad on Unix, since all Unix Ping APIs do nothing except report TimedOut for any non-success response (TtlExpired is not a status that Unix APIs will return under any circumstances I've found, so traceroute on Unix is currently rather busted and always waits the full |
The EAP version of the API is just a wrapper around the TAP version. That wrapper uses
The problem is with certain sync contexts, particularly the one set by the |
|
@SeeminglyScience Thanks! I see. Not clear is it a bug or by-design for EAP. |
|
I would say that it's by design that the EAP version honors the current synch context, PowerShell just doesn't play well with the windows forms sync context implementation specifically. Or really any external sync context I would guess. |
|
I agree that it's by design for the EAP version. It's the right thing to invoke the callback in the current synchronization context. Library APIs themselves should always use the default sync context, but when interacting with the user code, it's the user's decision if the current sync context should be honored (though the EAP version API doesn't let you choose :)). But I guess there is a bug in the EAP version API, where the |
src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1
Outdated
Show resolved
Hide resolved
|
@daxian-dbw, successfully started retry of |
|
@SteveL-MSFT Please take another look when you have time. |
|
Seems like the bot isn't adding the status either way... interesting. Perhaps try editing the PR title / summary a bit and see if that triggers whatever webhook the bot may be using? |
|
@vexx32 Yeah, I will edit the title a bit to see if that helps. |
src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Show resolved
Hide resolved
|
@PoshChan Please retry windows |
|
@daxian-dbw, successfully started retry of |
iSazonov
left a comment
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.
With one minor comment.
test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1
Show resolved
Hide resolved
|
@SteveL-MSFT Can you please update your review? Thanks |
|
@SteveL-MSFT A gentle ping. Please take another look when you get a chance. |
|
@SteveL-MSFT ping again 👋 😃 |
|
I vote to have the fix in 7.0 servicing because users use often WinForms and now Out-ConsoleGridView. |
|
Moved the PR to |
|
🎉 Handy links: |
|
🎉 Handy links: |
…or sending ping requests (PowerShell#11517)
PR Summary
Fix #11418
When using
Ping.SendAsyncwith a callback, the callback will always be invoked in the synchronization context of the pipeline thread. When the current synchronization context of the thread is null, the default context is used which is the threadpool.In case the pipeline thread's synchronization context is set (for example, by constructing a WindowsForm object), the callback will be scheduled to run on the pipeline thread, which will result in a dead lock.
The fix is to use
Ping.SendPingAsync.Note about
SendAsyncandPingCompletedEventArgsNote that, when using
Ping.SendAsync,_pingCompleteArgs.Cancelledis never set totruewhen the task is cancelled byCtrl+c. Instead,_pingCompleteArgs.Erroris set with aPingExceptionwhoseInnerExceptionisTaskCanceledException.I think this is a bug in the
Ping.SendAsyncAPI, but didn't spend the time to dig into it.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.