fix race condition causing unobserved exception

This commit is contained in:
rafael-aero
2021-11-05 11:01:32 +01:00
parent 5bf9aa811d
commit 606bb019f7

View File

@@ -458,8 +458,23 @@ namespace ElectronNET.API
Task.Run(async () =>
{
await socket.ConnectAsync();
_connectedSocketTask.TrySetResult(socket); //Probably was already on the OnConnected call
try
{
if (!socket.Connected)
{
await socket.ConnectAsync();
_connectedSocketTask.TrySetResult(socket); //Probably was already on the OnConnected call
}
return;
}
catch (Exception e)
{
await Task.Delay(1000);
if (!socket.Connected)
{
LogError(e, "Failed to connect");
}
}
});
_socket = socket;