Electron.NET icon indicating copy to clipboard operation
Electron.NET copied to clipboard

Socket Disconnection Error

Open AykutToprak opened this issue 5 years ago • 15 comments

  • Version: 9.31.2
  • CLI Version: 9.31.2
  • Target: .NET Core 3.1

Got disconnect! Reason: transport close ASP.NET Core Application connected... global.electronsocket fVcXgik5tZt05sn7AAAB 2020-07-21T13:23:13.319Z stdout: BridgeConnector connected!

As it showed above socket are disconnected and reconnected again. This caused problem for IPC Listeners. I guess they are somehow removed. Is there any workaround to solve this? @GregorBiswanger

Similar issue : #442 #428

AykutToprak avatar Jul 21 '20 13:07 AykutToprak

I've been facing this issue too. One minute all IPC works properly, then a transport error appears and it doesn't try to reconnect. I'm using ElectronNET.CLI Version: 9.31.2.0 Here is the error that's being displayed.

Got disconnect! Reason: transport error
ASP.NET Core Application connected... global.electronsocket dZkuRoGtHpejWwBYAAAC 2020-07-29T11:42:47.602Z
stdout: BridgeConnector connected!

stdout: dbug: Microsoft.AspNetCore.Server.Kestrel[10]
      Connection id "0HM1JMHGH414A" disconnecting.
dbug: Microsoft.AspNetCore.Server.Kestrel[10]
      Connection id "0HM1JMHGH4149" disconnecting.

stdout: dbug: Microsoft.AspNetCore.Server.Kestrel[2]
      Connection id "0HM1JMHGH4149" stopped.
dbug: Microsoft.AspNetCore.Server.Kestrel[2]
      Connection id "0HM1JMHGH414A" stopped.

stdout: dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[7]
      Connection id "0HM1JMHGH4149" sending FIN because: "The Socket transport's send loop completed gracefully."

stdout: dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[7]
      Connection id "0HM1JMHGH414A" sending FIN because: "The Socket transport's send loop completed gracefully."

rakista112 avatar Jul 29 '20 11:07 rakista112

Normally the socket connection should restore the registrations. Have you lost these?

GregorBiswanger avatar Aug 14 '20 13:08 GregorBiswanger

Socket connection is restored however IPC Listeners are not. Commitications between front-end and back-end are completely disconnected

AykutToprak avatar Aug 20 '20 16:08 AykutToprak

I am encountering this issue as well. On some Windows 10 machines this leads to the situation where the app can not quit itself anymore. The main process is killed, but all remaining Electron processes as well as the ASP.NET core process run until they are force killed by any means (e.g. TaskManager).

EDIT: Here is an example if you invoke Electron.WindowManager.BrowserWindows.First().Maximize(); after the disconnect happened:

image

Gaulomatic avatar Oct 14 '20 23:10 Gaulomatic

When will it be fixed? This is very critical for me. Is there a way to temporarily fix this?

IIiKoBiT avatar Jan 17 '21 13:01 IIiKoBiT

@GregorBiswanger I didn't wait for an answer, I cloned the whole project and built it. The disconnect problem is gone and everything works well. But any resources stopped working for me, there are no icons and images, what could it be?

IIiKoBiT avatar Jan 19 '21 16:01 IIiKoBiT

I believe this is fixed as of 11.5.1 @GregorBiswanger

danatcofo avatar Jan 25 '21 16:01 danatcofo

@danatcofo Unfortunately, this bug is not fixed yet.

I'm facing this issue now too and I'm using the latest release 11.5.1

As @Gaulomatic pointed out, it seems that this issue depends on the machine. Our Software runs on 30-40 machines without any issue, but on 4 machines this issue happens frequently. I do not see any obvious difference between the machines which work and the machines which won't work.

  • All are physical machines (no VMs)
  • All running Windows 10 (1903 to 2004)
  • It happens irregularly (Sometimes it fails after 10 Minutes, sometimes it fails after a couple of hours (max 5))

@IIiKoBiT I don't quite understand how this bug can be fixed if I compile this project myself? Did you make additional make any changes to the code?

JollyRoger91 avatar Feb 16 '21 09:02 JollyRoger91

I can hardly reproduce it. We need support.

Here is a video of how you can install the missing features yourself and submit them as a pull request: https://youtu.be/Po-saU_Z6Ws

Please also test it with you.

GregorBiswanger avatar Jul 02 '21 10:07 GregorBiswanger

We are currently also using a .NET library to be able to communicate with Nodejs Socket.io, which has long been deprecated.

We need a new one that will continue to be maintained and will also work with the current Socket.io version. Can someone help us? We are also happy to do this together.

GregorBiswanger avatar Jul 02 '21 10:07 GregorBiswanger

The talk here is of SocketIoClientDotNet https://github.com/Quobject/SocketIoClientDotNet/

GregorBiswanger avatar Jul 02 '21 10:07 GregorBiswanger

@GregorBiswanger the socket.io-client-csharp package seems to be fairly similar. As long as we specify that the EIO is 3 (socket.io 2.x) rather than the default 4 (socket.io 3.x 4.x). It seems to be updated fairly regularly.

tub5 avatar Jul 05 '21 08:07 tub5

I can hardly reproduce it. We need support.

Here is a video of how you can install the missing features yourself and submit them as a pull request: https://youtu.be/Po-saU_Z6Ws

Please also test it with you.

I'm able to reproduce this problem fairly consistently when calling BrowserWindow.GetBoundsAsync. When I programmatically resize the window, I can call GetBoundsAsync and there seems to be no problem. However, when I call the same method after a user resize event, i.e., inside an event handler for the BrowserWindow.OnResize, then the await window.GetBoundsAsync() never returns and eventually there is a socket disconnect.

pvenky avatar Jul 09 '21 04:07 pvenky

Is there any way to handled that issue manually from code?

dbphoton avatar Oct 12 '21 08:10 dbphoton

I'm encountering the same issue and I think I have pinned it down to being caused by a large json (~500KB) document being transmitted from the backend to the Electron App. What's weird is, that different computers seem to have different limits here. Maybe this helps.

Krizzzn avatar Jul 07 '22 07:07 Krizzzn

In my case the solution was as simple as making sure my System.Threading.Timer was disposed.

Not disposing it caused this error.

If it's any use to a developer, here's a (not isolated) function where it would occur. I create a Timer to update my Blazor component every 50 milliseconds, excluding the using caused the bug.

I'll try to reproduce it later on shareable code, but it seems like more of a user error issue than an electron one.

    public async Task<bool> Decrypt(VaultItem item) {
        var hmac = JsonConvert.DeserializeObject<byte[]>(item.Description.Properties["HMAC"]);
        var name = (string)item.Values["File Name"].Data;
        var size = (long)item.Values["Size"].Data;
        var key = Convert.FromBase64String((string)item.Values["Key"].Data);
        var out_path = await folder.SaveAsFile("Export File From Vault", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), name));


        if (out_path == null) return false;
        var enc_path = ad.State.Vaults.Active.Files.GetEncryptedFilePath(hmac);
        using var input_stream = File.OpenRead(enc_path);

        try
        {
            bool canceled = false;
            is_processing = true;
            process_text = "Decrypting " + name;
            await InvokeAsync(StateHasChanged);
            int previous_progress;

            // remove the using here to cause the bug
            using var timer = new System.Threading.Timer(async _ =>
            {
                previous_progress = progress;
                progress = (int)((input_stream.Position * 100 / size));
                if (cancel)
                {
                    if (!canceled) input_stream.Close();
                    canceled = true;
                }
                if (progress != previous_progress) await InvokeAsync(StateHasChanged);
            }, null, 0, 100);

            await ad.State.Vaults.Active.Files.Export(input_stream, hmac, key, out_path);
            is_done = true;
            is_processing = false;
            await InvokeAsync(StateHasChanged);
            snack_bar.Add($"Exported file to disk.", Severity.Success);
        }
        catch (Exception ex) {
            if (!cancel) snack_bar.Add($"Failed to decrypt file: {ex.Message}", Severity.Error);
        }

        is_done = false;
        cancel = false;
        progress = 0;
        process_text = null;
        is_processing = false;
        return true;
    }

jamieyello avatar Nov 30 '22 18:11 jamieyello

🎉🚀 New Electron.NET version 23.6.1 released 🚀🎉

With native Electron 23 and .NET 6 support. Your problem should be fixed here. If you continue to have the problem, please let us know. Please note the correct updating of your API & CLI. Info in the README. Have fun!

GregorBiswanger avatar Mar 28 '23 15:03 GregorBiswanger

Hello everyone, I have this problem, my visual studio is .NET8 but I just cloned the repository, followed the steps and started the project. Can someone help me? Could .net8 be the cause of the problem?

ElectronHostHook handling started...
Invoke electron.cmd - in dir: C:\Git\Infis\electron.net-api-demos\obj\Host\node_modules\.bin
electron.cmd "..\..\main.js"

Electron Socket IO Port: 8000
Electron Socket started on port 8000 at 127.0.0.1
ASP.NET Core Port: 8001
stdout: Use Electron Port: 8000

ASP.NET Core Application connected... global.electronsocket RcG020kd_wqGtineAAAA 2023-12-18T19:22:00.715Z
ASP.NET Core Application connected... global.electronsocket RcG020kd_wqGtineAAAA 2023-12-18T19:22:03.168Z
ASP.NET Core Application connected... global.electronsocket RcG020kd_wqGtineAAAA 2023-12-18T19:22:03.187Z
Got disconnect! Reason: transport close
Got disconnect! Reason: ping timeout

Solved: Guys, I didn't see it, but my Electron CLI was outdated, I updated it using command dotnet tool update ElectronNET.CLI -g and now it works ✅

arthurvalentereis avatar Dec 18 '23 19:12 arthurvalentereis