Safe way to call FSocket::Recv

What is a safe way to call FSocket::Recv? In my game, it blocks indefinitely. Here is my code

if (!Socket->Wait(ESocketWaitConditions::WaitForRead, 
 Timespan::FromSeconds(0.1))) {       
						AppendError("Failed to recv from the server. Resetting");
            return SM_NO_MESSAGE;
					}
					Socket->Recv((uint8*)&receive_buffer[0] + receivedData, MAXIMUM_PACKET_SIZE, BytesRead);

This code works fine in the editor. But it is stuck at Recv in the shipping build when the server is closed. According to the documentation and my google search, the wait function should ensure that there is data to be received. If I put logging before and after the Recv, I can see that it is stuck at Recv.

What am I doing wrong here? Is there a simple way to set a timeout on Recv?

This somehow solved the problem. It does not make sense but it works…

          if (!Socket->Wait(ESocketWaitConditions::WaitForRead, FTimespan::FromSeconds(1))) {       
						AppendError("Failed to recv from the server. Resetting");
            return SM_NO_MESSAGE;
					}
          if (!Socket->Recv((uint8*)&receive_buffer[0] + receivedData,
                            MAXIMUM_PACKET_SIZE, BytesRead,
                            ESocketReceiveFlags::Type::None)) {
						AppendError("Failed to recv from the server. Resetting");
            return SM_NO_MESSAGE;
          }