Skip to content

Commit

Permalink
Remove exception when using SO_REUSEADDR on Linux (mono#3856)
Browse files Browse the repository at this point in the history
SO_REUSEADDR and SO_REUSEPORT are fundamentally different. This
exception seems to have been put in place to address the lack of
the latter on older Linux kernels for TCP. However, the change in
fact raises an exception when SO_REUSEADDR is used, which causes
failures in server applications, which may use SO_REUSEADDR to
avoid WAIT state timeouts.

Description of SO_REUSEADDR and SO_REUSEPORT differences:

http://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t

Some problems caused by raising this exception:

zeromq/netmq#623
zeromq/netmq#592
fsprojects/IfSharp#90
  • Loading branch information
sylvanc authored and luhenry committed Dec 6, 2016
1 parent 08fd525 commit c06bca9
Showing 1 changed file with 0 additions and 3 deletions.
3 changes: 0 additions & 3 deletions mcs/class/System/System.Net.Sockets/Socket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3193,9 +3193,6 @@ public void SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName opt
{
ThrowIfDisposedAndClosed ();

if (optionLevel == SocketOptionLevel.Socket && optionName == SocketOptionName.ReuseAddress && optionValue != 0 && !SupportsPortReuse (protocol_type))
throw new SocketException ((int) SocketError.OperationNotSupported, "Operating system sockets do not support ReuseAddress.\nIf your socket is not intended to bind to the same address and port multiple times remove this option, otherwise you should ignore this exception inside a try catch and check that ReuseAddress is true before binding to the same address and port multiple times.");

int error;
SetSocketOption_internal (safe_handle, optionLevel, optionName, null, null, optionValue, out error);

Expand Down

0 comments on commit c06bca9

Please sign in to comment.