Dotnetcore application hangs on IWebHostBuilder.Build() under linux


I have difficulties with running dotnetcore application as a service under Ubuntu 18.04.3 LTS. The application works OK on Windows, and most of the times on Ubuntu too. But several hosts on Ubuntu may start service, but web host won't initialize for several hours and then suddenly initialize without outside action, see example below. Journalctl won't show nothing interesting before sudden startup.

Apr 23 18:52:01 MyNode.Api[12276]: Running MyNode as console app
Apr 24 13:42:04 MyNode.Api[12276]: IWebHost is built

Service is starting OK, status is "running"

root@DSK06511:/home/monouser# service MyNode status
● MyNode.service - MyNode
   Loaded: loaded (/etc/systemd/system/MyNode.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2020-04-24 18:36:31 MSK; 5min ago
 Main PID: 10131 (MyNode)
    Tasks: 14 (limit: 4915)
   CGroup: /system.slice/MyNode.service
           ├─10131 /home/monouser/.octopus/Applications/OctopusServer/Production/MyNode.Linux/ --console
           ├─10220 /home/monouser/.octopus/Applications/OctopusServer/Production/MyNode.Linux/ --console
           ├─10264 /home/monouser/.octopus/Applications/OctopusServer/Production/MyNode.Linux/ --console
           └─10285 /home/monouser/.octopus/Applications/OctopusServer/Production/MyNode.Linux/ --console

Apr 24 18:36:31 systemd[1]: Started MyNode.
Apr 24 18:36:31 MyNode[10131]: Running MmNode as console app
Apr 24 18:36:31 MyNode[10131]: Building host...

Program.cs content is below:

public static async Task Main(string[] args)
    var isService = !Debugger.IsAttached && !args.Contains(ConsoleRunOption);
    Console.WriteLine("Running as " + (isService ? "service" : "console app"));
    IWebHostBuilder builder = null;
        builder = CreateWebHostBuilder(args.Where(p => p != ConsoleRunOption).ToArray());
    catch (Exception e)
        // logging here details...

    if (isService)
        var host = builder.Build();
        using ServiceBase service = new ProgramHostService(host);
        Console.WriteLine("After ServiceBase.Run");
        Console.WriteLine("Building host...");   //this is the last line written to console
        var host = builder.Build();              //hangs here
        Console.WriteLine("IWebHost is built");  //may finish in hours
        var initializer = host.Services.GetRequiredService<Initializer>();
        Console.WriteLine("Running InitializeAsync...");
        await initializer.InitializeAsync();
        Console.WriteLine("Running IWebHost...");

My service file is run as .../MyNode --console (see full below):

root@DSK06511:/home/monouser# cat  /etc/systemd/system/MyNode.service



ExecStart=/home/monouser/.octopus/Applications/OctopusServer/Production/MyNode.Linux/ --console


Unfortunately taking dotnet-dump also won't work with the error Writing dump failed (HRESULT: 0x80004005) but that's out of scope.

I'm guessing the service is configured wrong somehow, but what causes it to work sometimes and sometimes not?.. Thanks in advance.

asked on Stack Overflow Apr 24, 2020 by flam3 • edited Apr 25, 2020 by flam3

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0