From 7f5db58edd0113904e0db4e37071795845eece0f Mon Sep 17 00:00:00 2001 From: theolivenbaum Date: Thu, 2 Sep 2021 20:06:01 +0200 Subject: [PATCH] fix deadlock case on emit before any Socket use --- ElectronNET.API/BridgeConnector.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ElectronNET.API/BridgeConnector.cs b/ElectronNET.API/BridgeConnector.cs index 1a36934..06db94d 100644 --- a/ElectronNET.API/BridgeConnector.cs +++ b/ElectronNET.API/BridgeConnector.cs @@ -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;