Bug 18976 - System.Net.Sockets.Socket Select_internal Error Reporting
Summary: System.Net.Sockets.Socket Select_internal Error Reporting
Status: NEEDINFO
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-04-12 23:34 UTC by Sean Hanna
Modified: 2014-05-24 10:29 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Sean Hanna 2014-04-12 23:34:23 UTC
System.Net.Sockets.Sockets defines icall to ves_icall_System_Net_Sockets_Socket_Select_internal()

This function in turn invokes mono_poll() which uses the *nix errno style format for error reporting. So even in the win32 builds, it takes the winsock select() error codes and maps them to EINTR / EFAULT /EBADF / etc.. error codes.

This ves_icall_System_Net_Sockets_Socket_Select_internal() function passes the *nix errno style error code to caller in an out variable.

This is used by Select() also defined in System.Net.Sockets.Socket

public static void Select (IList checkRead, IList checkWrite, IList checkError, int microSeconds)

When an error occurs the error code (in *nix format) is passed into SocketException (which derives from Win32Exception) and so the *nix format error code is mapped to the equivalent win32 error message directly, and this is an incompatible error code per http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx

EINTR = 0x4

Windows 0x4 = ERROR_TOO_MANY_OPEN_FILES

    4 (0x4)

    The system cannot open the file.

EFAULT = 0xE
Windows 0xE = ERROR_OUTOFMEMORY

    14 (0xE)

    Not enough storage is available to complete this operation.


I'm not really messing around with sockets so don't have a test case to provide, but noticed this while browsing the code and decided to share.
Comment 1 Miguel de Icaza [MSFT] 2014-05-23 10:49:53 UTC
Sean, 

Do you have a test case for when this is happening?
Comment 2 Sean Hanna 2014-05-24 10:29:42 UTC
Nope, though i guess you'd start by finding a way to cause mono_poll() to fail with an error. So make poll() fail in environments that have poll(), and you could to go after select() on win32 / apple (if i'm reading it right).

poll() / select() is a blocking operation so that makes it easier. you could probably spin up a socket, kill the fd, and then call select, which will give EFAULT because the fd no longer exists?

Socket s = new Socket(AddressFamily.InterNetwork,
                             SocketType.Stream,
                             ProtocolType.Tcp);
  s.Bind(new IPEndPoint(ipAddress, 11000 + i));
  s.Listen(10);

s.Close();

s.Dispose();

Socket.Select(new[] { s }, null, null, -1);

This is just a mess i threw together in a few minutes, but it might be a starting point

Note You need to log in before you can comment on or make changes to this bug.