Missed some context in the problem description. The socket was bound to an I/O completion port. The function call failed but result of ConnectEx was received through GetQueuedCompletionStatus in a worker thread.
EDIT:
I should have called WSAGetLastError()
instead.