Skip to content
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

Optimize AppVeyor network stack for number of dynamic connections #922

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

IgorMilavec
Copy link
Collaborator

Many internet sources indicate that the root cause for System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted. is port exhaustion. In case of SSH.NET tests, this could be caused by a large number of connections opened and closed in quick succession. This was already discussed in #877 (comment).

In this PR I have both increased the number of ports that can be used for client side connections and decreased the time that the network stack needs to wait before reusing bindings. More information on these settings here.
As this only affects the AppVeyor build VM, I do not expect any regressions or side effects.

This will (hopefully) fix #921.

appveyor.yml Outdated
@@ -1,5 +1,9 @@
os: Visual Studio 2019

init:
- netsh int ipv4 set dynamicport tcp start=1025 num=64510
- powershell "New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters' -Name 'TcpTimedWaitDelay' -Value '15' -PropertyType 'DWord'"
Copy link
Contributor

@zybexXL zybexXL Feb 19, 2022

Choose a reason for hiding this comment

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

This setting requires this other key to be set or it will have no effect: (Source)

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]
"StrictTimeWaitSeqCheck"=dword:00000001

It also only takes effect after reboot, so if the AppVeyor VM reverts to base settings on each reboot this will also have no effect.

Third, both commands require Elevation. Does AppVeyor execute this as Admin? I find it unlikely.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, AppVeyor build VM is started fresh from image. So there is no point in setting this registry setting... do you know of any other method for setting wait delay that would be effective immediately?

Copy link
Contributor

@zybexXL zybexXL Feb 19, 2022

Choose a reason for hiding this comment

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

Perhaps we can set the per-socket timeout when running the test Suite?

// sets the amount of time to linger after closing, using the LingerOption public property.
LingerOption lingerOption = new LingerOption (true, 10);

SO_REUSEPORT or SO_REUSEADDR seem to be more appropriate, but it looks like Windows doesn't really care about these flags.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cool, this would work. But I think this amount of changes is beyond this PR and should be discussed further. For now I'll just remove the wait delay change as is is ineffective and leave the enlargement of client port pool in this PR.

@IgorMilavec IgorMilavec marked this pull request as draft February 19, 2022 17:30
@IgorMilavec IgorMilavec marked this pull request as ready for review February 19, 2022 19:48
appveyor.yml Show resolved Hide resolved
@Rob-Hague Rob-Hague mentioned this pull request Oct 21, 2023
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.

AppVeyor test runs fail with "Only one usage of each socket address is normally permitted"
2 participants