Fixed: CPU locking at a 100% in certain instances. (#2258) (Fixes #2218)

Mike 7 years ago committed by Leonardo Galli
parent 5dc2df3d49
commit e4a3e63c44

@ -1,4 +1,4 @@
using System; using System;
using System.Net.Sockets; using System.Net.Sockets;
using NLog; using NLog;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
@ -11,6 +11,13 @@ namespace NzbDrone.Console
{ {
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(ConsoleApp)); private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(ConsoleApp));
private enum ExitCodes : int
{
Normal = 0,
UnknownFailure = 1,
RecoverableFailure = 2
}
public static void Main(string[] args) public static void Main(string[] args)
{ {
try try
@ -19,30 +26,41 @@ namespace NzbDrone.Console
NzbDroneLogger.Register(startupArgs, false, true); NzbDroneLogger.Register(startupArgs, false, true);
Bootstrap.Start(startupArgs, new ConsoleAlerts()); Bootstrap.Start(startupArgs, new ConsoleAlerts());
} }
catch (SocketException exception) catch (SocketException e)
{ {
System.Console.WriteLine(""); System.Console.WriteLine("");
System.Console.WriteLine(""); System.Console.WriteLine("");
Logger.Fatal(exception.Message + ". This can happen if another instance of Radarr is already running another application is using the same port (default: 7878) or the user has insufficient permissions"); Logger.Fatal(e.Message + ". This can happen if another instance of Radarr is already running another application is using the same port (default: 7878) or the user has insufficient permissions");
System.Console.WriteLine("Press enter to exit..."); Exit(ExitCodes.RecoverableFailure);
System.Console.ReadLine();
Environment.Exit(1);
} }
catch (Exception e) catch (Exception e)
{ {
System.Console.WriteLine(""); System.Console.WriteLine("");
System.Console.WriteLine(""); System.Console.WriteLine("");
Logger.Fatal(e, "EPIC FAIL!"); Logger.Fatal(e, "EPIC FAIL!");
System.Console.WriteLine("Press enter to exit..."); Exit(ExitCodes.UnknownFailure);
System.Console.ReadLine();
Environment.Exit(1);
} }
Logger.Info("Exiting main."); Logger.Info("Exiting main.");
//Need this to terminate on mono (thanks nlog) Exit(ExitCodes.Normal);
LogManager.Configuration = null; }
Environment.Exit(0);
private static void Exit(ExitCodes exitCode)
{
LogManager.Shutdown();
if (exitCode != ExitCodes.Normal)
{
System.Console.WriteLine("Press enter to exit...");
System.Threading.Thread.Sleep(1000);
// Please note that ReadLine silently succeeds if there is no console, KeyAvailable does not.
System.Console.ReadLine();
}
Environment.Exit((int)exitCode);
} }
} }
} }

@ -4,6 +4,7 @@ using NLog;
using NzbDrone.Common.Composition; using NzbDrone.Common.Composition;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using Radarr.Host.Owin; using Radarr.Host.Owin;
@ -56,6 +57,7 @@ namespace Radarr.Host
} }
_runtimeInfo.IsRunning = true; _runtimeInfo.IsRunning = true;
DbFactory.RegisterDatabase(_container);
_hostController.StartServer(); _hostController.StartServer();
if (!_startupContext.Flags.Contains(StartupContext.NO_BROWSER) if (!_startupContext.Flags.Contains(StartupContext.NO_BROWSER)

@ -1,4 +1,4 @@
using System; using System;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using NLog; using NLog;
@ -7,7 +7,6 @@ using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Instrumentation;
using NzbDrone.Common.Processes; using NzbDrone.Common.Processes;
using NzbDrone.Common.Security; using NzbDrone.Common.Security;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Instrumentation;
namespace Radarr.Host namespace Radarr.Host
@ -43,7 +42,6 @@ namespace Radarr.Host
{ {
startCallback(_container); startCallback(_container);
} }
else else
{ {
SpinToExit(appMode); SpinToExit(appMode);
@ -69,8 +67,7 @@ namespace Radarr.Host
EnsureSingleInstance(applicationModes == ApplicationModes.Service, startupContext); EnsureSingleInstance(applicationModes == ApplicationModes.Service, startupContext);
} }
DbFactory.RegisterDatabase(_container);
_container.Resolve<Router>().Route(applicationModes); _container.Resolve<Router>().Route(applicationModes);
} }

Loading…
Cancel
Save