fix deadlock case on emit before any Socket use

This commit is contained in:
theolivenbaum
2021-09-02 20:06:01 +02:00
parent d18700f64d
commit 7f5db58edd

View File

@@ -93,7 +93,17 @@ namespace ElectronNET.API
private static TaskCompletionSource _waitForBeingConnected = new TaskCompletionSource();
private static Task _waitForConnection => _waitForBeingConnected.Task;
private static Task _waitForConnection
{
get
{
if(_socket is null)
{
var _ = Socket; //Ensure we trigger the first connection before anything else
}
return _waitForBeingConnected.Task;
}
}
public static bool IsConnected => _waitForConnection is Task task && task.IsCompletedSuccessfully;
@@ -414,7 +424,7 @@ namespace ElectronNET.API
socket.OnDisconnected += async (_, reason) =>
{
Log("ElectronNET socket disconnected with reason {0}, trying to reconnect on port {1}!", reason, BridgeSettings.SocketPort);
_waitForBeingConnected = new();
int i = 0;