[WIP] Stop setting SO_REUSEADDR to fix Port Forwarding #654
[WIP] Stop setting SO_REUSEADDR to fix Port Forwarding #654vthiebaut10 wants to merge 2 commits intoPowerShell:latestw_allfrom
Conversation
…rt on forwarding scenarios
|
To ensure proper socket reuse on Windows without using SO_REUSEADDR, you can use the SO_EXCLUSIVEADDRUSE option instead. This option prevents multiple sockets from binding to the same port, which helps avoid the indeterminate behavior caused by SO_REUSEADDR. Here’s how you can approach it:
By using SO_EXCLUSIVEADDRUSE and ensuring proper socket management, you can achieve reliable socket reuse on Windows without relying on SO_REUSEADDR. |
|
The current behavior allows multiple processes to bind the same port without failure. |
Fix: PowerShell/Win32-OpenSSH#1968
PR Summary
SO_REUSEADDR socket option means different things on Windows and *nix systems.
On Windows, that option allows sockets to forcibly bind to ports in use by other sockets. The behavior for all sockets once the second socket is bound to the port is indeterminate. (See: https://learn.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruse#using-so_reuseaddr)
On *nix systems, the SO_REUSEADDR is used to address edge cases that might occur after socket termination. It allows the socket to be reused while it is on TIME_WAIT state. It still returns "Address already in use" error if the socket is being used while in any other state. (See: https://stackoverflow.com/questions/3229860/what-is-the-meaning-of-so-reuseaddr-setsockopt-option-linux)
Supposedly, Windows doesn't have the issue of preventing the reutilization of sockets during TIME_WAIT (according to this discussion: warmcat/libwebsockets#65 (comment)), so there should be no value for us to use the SO_REUSEADDR when creating sockets.