Commit f75a8b35 authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

winhttp/tests: Avoid race condition on closing connection in server_thread().

The connection may be cached and checked for availability for request before the server thread closes it.
parent 645a65cb
......@@ -1401,7 +1401,7 @@ struct server_info
};
static int server_socket;
static HANDLE server_socket_available, server_socket_done;
static HANDLE server_socket_available, server_socket_closed, server_socket_done;
static DWORD CALLBACK server_thread(LPVOID param)
{
......@@ -1436,7 +1436,7 @@ static DWORD CALLBACK server_thread(LPVOID param)
do
{
if (c == -1) c = accept(s, NULL, NULL);
ResetEvent(server_socket_closed);
memset(buffer, 0, sizeof buffer);
for(i = 0; i < sizeof buffer - 1; i++)
{
......@@ -1463,6 +1463,7 @@ static DWORD CALLBACK server_thread(LPVOID param)
}
shutdown(c, 2);
closesocket(c);
SetEvent(server_socket_closed);
c = -1;
} while (!last_request);
......@@ -1749,6 +1750,7 @@ static void test_persistent_connection(int port)
SetEvent( server_socket_done );
CloseHandle( info.wait );
WaitForSingleObject( server_socket_closed, INFINITE );
}
struct test_recursion_context
......@@ -1929,6 +1931,7 @@ START_TEST (notification)
ok( thread != NULL, "failed to create thread %lu\n", GetLastError() );
server_socket_available = CreateEventW( NULL, 0, 0, NULL );
server_socket_closed = CreateEventW( NULL, 0, 0, NULL );
server_socket_done = CreateEventW( NULL, 0, 0, NULL );
ret = WaitForSingleObject( si.event, 10000 );
......@@ -1948,4 +1951,5 @@ START_TEST (notification)
CloseHandle( thread );
CloseHandle( server_socket_available );
CloseHandle( server_socket_done );
CloseHandle( server_socket_closed );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment