Browse Source

Ignore enotconn error results from the socket shutdown API

Katelyn Gadd 7 years ago
parent
commit
6d7167f2f6
1 changed files with 13 additions and 1 deletions
  1. 13 1
      mcs/class/System/System.Net.Sockets/Socket.cs

+ 13 - 1
mcs/class/System/System.Net.Sockets/Socket.cs

@@ -2608,14 +2608,26 @@ namespace System.Net.Sockets
 
 		public void Shutdown (SocketShutdown how)
 		{
+			const int enotconn = 10057;
+
 			ThrowIfDisposedAndClosed ();
 
 			if (!is_connected)
-				throw new SocketException (10057); // Not connected
+				throw new SocketException (enotconn); // Not connected
 
 			int error;
 			Shutdown_internal (m_Handle, how, out error);
 
+			if (error == enotconn) {
+				// POSIX requires this error to be returned from shutdown in some cases,
+				//  even if the socket is actually connected.
+				// We have already checked is_connected so it isn't meaningful or useful for
+				//  us to throw if the OS says the socket was already closed when we tried to
+				//  shut it down.
+				// See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=227259
+				return;
+			}
+
 			if (error != 0)
 				throw new SocketException (error);
 		}