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:
Andrew Camilleri
2021-04-01 05:27:22 +02:00
committed by GitHub
parent 64db865e1e
commit 6ead5c3800
5 changed files with 139 additions and 6 deletions

View File

@@ -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();