From 11743177c75c480476fc46d64f2206e8b59a967d Mon Sep 17 00:00:00 2001 From: Marcos Henrich Date: Tue, 7 Jun 2016 14:06:53 +0100 Subject: [PATCH] [runtime] Fixed interruptible wapi_sendfile. Before closing a socket we try to interrupt and wait for all socket pending system calls to return. For that we set the socket as non blocking which makes the system calls to return with EAGAIN\EWOULDBLOCK. This issue was caught by System.Net.Sockets.SocketTest.SendAsyncFile that was intermittently failing, we were only able to reproduce it while running multiple test suites in parallel. We now can say that it only failed when the the socket was closed and the sendfile was waiting for the OS to allocate enough resources to send the file. This was fixed by changing wapi_sendfile to return on EAGAIN. --- mono/io-layer/sockets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mono/io-layer/sockets.c b/mono/io-layer/sockets.c index aaa53ffe16d..6d0da527bd6 100644 --- a/mono/io-layer/sockets.c +++ b/mono/io-layer/sockets.c @@ -969,7 +969,7 @@ wapi_sendfile (guint32 socket, gpointer fd, guint32 bytes_to_write, guint32 byte /* TODO: Might not send the entire file for non-blocking sockets */ res = sendfile (file, socket, 0, &statbuf.st_size, NULL, 0); #endif - } while (res != -1 && (errno == EINTR || errno == EAGAIN) && !_wapi_thread_cur_apc_pending ()); + } while (res != -1 && errno == EINTR && !_wapi_thread_cur_apc_pending ()); if (res == -1) { errnum = errno; errnum = errno_to_WSA (errnum, __func__); -- 2.25.1