FRunnable thread freezes editor

Hi,

I’m creating a FRunnable on UGameInstance.Init() with FRunnableThread::Create

In Run() function I’m reading from a socket with recv and the thread gets locked waiting for data.
If I stop the editor it freezes waiting for thread to finalize.
I override Shutdown() and BeginDestroy() in UGameInstance closing the socket with closesocket but this functions are never called.

Anybody knows why this functions are never called and how can I solve it?
Thank you in advance.

Could you show some code of your run function so that I know what youre doing? It’s possible that run is never finished and the main thread will freeze trying to destroy the thread when waiting for it to finish first.

Sure… As I said recv func locks the thread. If the main thread tries to destroy it I don’t understand how the cleanup works because Stop() is never called.

uint32 SocketManager::Run()
{
	while (true)
	{
		int32 iResult = recv(wsSocket, recvbuf, BUFLEN, 0);
		if (iResult <= 0)
		{
			break;
		}
	}

	return 0;
}

void SocketManager::Stop()
{
	if (wsSocket != INVALID_SOCKET)
	{
		closesocket(wsSocket);
		wsSocket = INVALID_SOCKET;
	}
}

Can anybody help me?
If anyone knows any other way to do it I would be very grateful that inicase me how.
Thank you.

Resolved. Thanks.

How did you solve the problem??

This was probably fixed by adding a sleep in the while loop:

FPlatformProcess::Sleep(0.001f);