diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 9cae18f5b16f40a3f12455e4d7bd076e03d5db3b..06f1c26d7dd31efb731cc246db6d7aba34892c8f 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -3586,7 +3586,13 @@ static BOOL WINAPI WS2_ConnectEx(SOCKET s, const struct WS_sockaddr* name, int n
 
             /* If the connect already failed */
             if (status == STATUS_PIPE_DISCONNECTED)
-                status = _get_sock_error(s, FD_CONNECT_BIT);
+            {
+                ov->Internal = _get_sock_error(s, FD_CONNECT_BIT);
+                ov->InternalHigh = 0;
+                if (cvalue) WS_AddCompletion( s, cvalue, ov->Internal, ov->InternalHigh );
+                if (ov->hEvent) NtSetEvent( ov->hEvent, NULL );
+                status = STATUS_PENDING;
+            }
             SetLastError( NtStatusToWSAError(status) );
         }
     }
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 43008cf6ca4c20011fa234c32ba3aef3970f5f80..897839a7a0df1c827dd2d54660211fc8ce7dd287 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -7915,22 +7915,14 @@ static void test_ConnectEx(void)
     address.sin_port = htons(1);
 
     bret = pConnectEx(connector, (struct sockaddr*)&address, addrlen, NULL, 0, &bytesReturned, &overlapped);
-    ok(bret == FALSE && GetLastError(), "ConnectEx to bad destination failed: "
+    ok(bret == FALSE && GetLastError() == ERROR_IO_PENDING, "ConnectEx to bad destination failed: "
         "returned %d + errno %d\n", bret, GetLastError());
+    dwret = WaitForSingleObject(overlapped.hEvent, 15000);
+    ok(dwret == WAIT_OBJECT_0, "Waiting for connect event failed with %d + errno %d\n", dwret, GetLastError());
 
-    if (GetLastError() == ERROR_IO_PENDING)
-    {
-        dwret = WaitForSingleObject(overlapped.hEvent, 15000);
-        ok(dwret == WAIT_OBJECT_0, "Waiting for connect event failed with %d + errno %d\n", dwret, GetLastError());
-
-        bret = GetOverlappedResult((HANDLE)connector, &overlapped, &bytesReturned, FALSE);
-        ok(bret == FALSE && GetLastError() == ERROR_CONNECTION_REFUSED,
-           "Connecting to a disconnected host returned error %d - %d\n", bret, WSAGetLastError());
-    }
-    else {
-        ok(GetLastError() == WSAECONNREFUSED,
-           "Connecting to a disconnected host returned error %d - %d\n", bret, WSAGetLastError());
-    }
+    bret = GetOverlappedResult((HANDLE)connector, &overlapped, &bytesReturned, FALSE);
+    ok(bret == FALSE && GetLastError() == ERROR_CONNECTION_REFUSED,
+       "Connecting to a disconnected host returned error %d - %d\n", bret, WSAGetLastError());
 
 end:
     if (overlapped.hEvent)