mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Plugin FailSafe (#2351)
This introduces the concept of plugins being disabled in the case of an unrecoverable runtime error caused by a plugin.
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Runtime.CompilerServices;
|
||||
using BTCPayServer.Configuration;
|
||||
using BTCPayServer.Hosting;
|
||||
using BTCPayServer.Logging;
|
||||
using BTCPayServer.Plugins;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Hosting.Server.Features;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
[assembly: InternalsVisibleTo("BTCPayServer.Tests")]
|
||||
@@ -22,10 +25,11 @@ namespace BTCPayServer
|
||||
using var loggerFactory = new LoggerFactory();
|
||||
loggerFactory.AddProvider(loggerProvider);
|
||||
var logger = loggerFactory.CreateLogger("Configuration");
|
||||
IConfiguration conf = null;
|
||||
try
|
||||
{
|
||||
// This is the only way that LoadArgs can print to console. Because LoadArgs is called by the HostBuilder before Logs.Configure is called
|
||||
var conf = new DefaultConfiguration() { Logger = logger }.CreateConfiguration(args);
|
||||
conf = new DefaultConfiguration() { Logger = logger }.CreateConfiguration(args);
|
||||
if (conf == null)
|
||||
return;
|
||||
Logs.Configure(loggerFactory);
|
||||
@@ -60,6 +64,11 @@ namespace BTCPayServer
|
||||
if (!string.IsNullOrEmpty(ex.Message))
|
||||
Logs.Configuration.LogError(ex.Message);
|
||||
}
|
||||
catch(Exception e) when( PluginManager.IsExceptionByPlugin(e))
|
||||
{
|
||||
var pluginDir = new DataDirectories().Configure(conf).PluginDir;
|
||||
PluginManager.DisablePlugin(pluginDir, e.Source);
|
||||
}
|
||||
finally
|
||||
{
|
||||
processor.Dispose();
|
||||
|
||||
Reference in New Issue
Block a user