Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get properties that use Task.Run().Result seem to block execution #431

Closed
freosc opened this issue Jun 12, 2020 · 2 comments · Fixed by #595
Closed

Get properties that use Task.Run().Result seem to block execution #431

freosc opened this issue Jun 12, 2020 · 2 comments · Fixed by #595
Labels

Comments

@freosc
Copy link
Contributor

freosc commented Jun 12, 2020

  • Version: latest from github 9.31.1

.net core 3.1 node 12.16.3

  • Target: win

Steps to Reproduce:

  1. In the demo Electron.Net WebApp, in ElectronBootstrap, I added these lines of code
Console.WriteLine("set AllowDowngrade");
Electron.AutoUpdater.AllowDowngrade = true;
Console.WriteLine("get AllowDowngrade");
//Code execution blocks on the following line
bool allowDowngrade = Electron.AutoUpdater.AllowDowngrade;
Console.WriteLine("AllowDowngrade: " + allowDowngrade);
  1. The set property works fine, but I noticed that the get property blocks execution, so the console won't show the last line in the code block above.
    Inside the property getter code I see that the code is executed correctly, but the socket.on "autoUpdater-allowDowngrade-get-reply" event is never fired.

This bug occurs for all property getters in the electron.net code that use the Task.Run().Result pattern

(Sidenote: a few seconds after the code execution is blocked, the socket also disconnects)

@freosc freosc added the bug label Jun 12, 2020
@freosc
Copy link
Contributor Author

freosc commented Jun 14, 2020

I discovered that it does work in sync methods, and doesn't work in async methods.
If you put the example lines of code inside the Program.CreateWebHostBuilder, like this:

public static IWebHostBuilder CreateWebHostBuilder(string[] args)
        {
            var x = WebHost.CreateDefaultBuilder(args)
                .ConfigureLogging((hostingContext, logging) => { logging.AddConsole(); })
                .UseElectron(args)
                .UseStartup<Startup>();

            Console.WriteLine("set AllowDowngrade");
            Electron.AutoUpdater.AllowDowngrade = true;
            Console.WriteLine("get AllowDowngrade");
            //Code execution blocks on the following line
            bool allowDowngrade = Electron.AutoUpdater.AllowDowngrade;
            Console.WriteLine("AllowDowngrade: " + allowDowngrade);

            return x;
        }

This will work. But it'll fail when ran from an async method such as the async ElectronBootstrap()
in your demo webapp, or in case somewhere upstream in the stacktrace an async method is used.

I guess we're looking at the infamous async deadlock issue, described here:
https://blog.stephencleary.com/2012/07/dont-block-on-async-code.html

@theolivenbaum
Copy link

Is there anyone working on the remaining .Result uses? Happy to jump with a PR if not...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants