-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fix plugin exception #3426
Merged
Merged
Fix plugin exception #3426
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a7f39ef
Revert "Revert "Plugin unhandled exception (#3349)" (#3366)"
Jim8y ffcd7ce
ensure leveldb is not used in multithread env
Jim8y a4cade1
Revert "Revert "Plugin unhandled exception (#3349)" (#3366)"
Jim8y 5ebdfd4
remove async.
Jim8y 82fcfb6
Update src/Neo/Plugins/UnhandledExceptionPolicy.cs
Jim8y da31567
Merge branch 'fix-plugin-exception' of github.com:Jim8y/neo into fix-…
Jim8y ba3e748
not use linq
Jim8y 0a41a97
Merge branch 'master' into fix-plugin-exception
shargon b76adb9
Merge branch 'master' into fix-plugin-exception
Jim8y 5a7443f
Update src/Neo/Plugins/UnhandledExceptionPolicy.cs
shargon c9e6dd4
use ignore case
shargon 3944f42
Update src/Plugins/TokensTracker/TokensTracker.cs
shargon 79d597c
Merge branch 'master' into fix-plugin-exception
Jim8y 5034e7f
Update src/Neo/Plugins/Plugin.cs
Jim8y b384811
Merge branch 'master' into fix-plugin-exception
Jim8y 2ecf454
Merge branch 'master' into fix-plugin-exception
Jim8y 1a80344
Merge branch 'master' into fix-plugin-exception
NGDAdmin e4b10cb
Merge branch 'master' into fix-plugin-exception
shargon 07906b2
Merge branch 'master' into fix-plugin-exception
NGDAdmin eb0c6b4
Merge branch 'master' into fix-plugin-exception
NGDAdmin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
using Akka.Actor; | ||
using Akka.Configuration; | ||
using Akka.IO; | ||
using Akka.Util.Internal; | ||
using Neo.IO.Actors; | ||
using Neo.Network.P2P; | ||
using Neo.Network.P2P.Payloads; | ||
|
@@ -22,12 +21,11 @@ | |
using Neo.SmartContract.Native; | ||
using Neo.VM; | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Neo.Ledger | ||
{ | ||
|
@@ -472,10 +470,10 @@ private void Persist(Block block) | |
Context.System.EventStream.Publish(application_executed); | ||
all_application_executed.Add(application_executed); | ||
} | ||
_ = InvokeCommittingAsync(system, block, snapshot, all_application_executed); | ||
InvokeCommitting(system, block, snapshot, all_application_executed); | ||
snapshot.Commit(); | ||
} | ||
_ = InvokeCommittedAsync(system, block); | ||
InvokeCommitted(system, block); | ||
system.MemPool.UpdatePoolForBlockPersisted(block, system.StoreView); | ||
extensibleWitnessWhiteList = null; | ||
block_cache.Remove(block.PrevHash); | ||
|
@@ -484,39 +482,40 @@ private void Persist(Block block) | |
Debug.Assert(header.Index == block.Index); | ||
} | ||
|
||
internal static async Task InvokeCommittingAsync(NeoSystem system, Block block, DataCache snapshot, IReadOnlyList<ApplicationExecuted> applicationExecutedList) | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal static void InvokeCommitting(NeoSystem system, Block block, DataCache snapshot, IReadOnlyList<ApplicationExecuted> applicationExecutedList) | ||
{ | ||
await InvokeHandlersAsync(Committing?.GetInvocationList(), h => ((CommittingHandler)h)(system, block, snapshot, applicationExecutedList)); | ||
InvokeHandlers(Committing?.GetInvocationList(), h => ((CommittingHandler)h)(system, block, snapshot, applicationExecutedList)); | ||
} | ||
|
||
internal static async Task InvokeCommittedAsync(NeoSystem system, Block block) | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal static void InvokeCommitted(NeoSystem system, Block block) | ||
{ | ||
await InvokeHandlersAsync(Committed?.GetInvocationList(), h => ((CommittedHandler)h)(system, block)); | ||
InvokeHandlers(Committed?.GetInvocationList(), h => ((CommittedHandler)h)(system, block)); | ||
} | ||
|
||
private static async Task InvokeHandlersAsync(Delegate[] handlers, Action<Delegate> handlerAction) | ||
private static void InvokeHandlers(Delegate[] handlers, Action<Delegate> handlerAction) | ||
{ | ||
if (handlers == null) return; | ||
|
||
var exceptions = new ConcurrentBag<Exception>(); | ||
var tasks = handlers.Select(handler => Task.Run(() => | ||
foreach (var handler in handlers) | ||
{ | ||
try | ||
{ | ||
// skip stopped plugin. | ||
if (handler.Target is Plugin { IsStopped: true }) | ||
{ | ||
return; | ||
continue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the stopped plugin keep crashing nothing will be reported? |
||
} | ||
|
||
handlerAction(handler); | ||
} | ||
catch (Exception ex) when (handler.Target is Plugin plugin) | ||
{ | ||
Utility.Log(nameof(plugin), LogLevel.Error, ex); | ||
switch (plugin.ExceptionPolicy) | ||
{ | ||
case UnhandledExceptionPolicy.StopNode: | ||
exceptions.Add(ex); | ||
throw; | ||
case UnhandledExceptionPolicy.StopPlugin: | ||
//Stop plugin on exception | ||
|
@@ -526,20 +525,11 @@ private static async Task InvokeHandlersAsync(Delegate[] handlers, Action<Delega | |
// Log the exception and continue with the next handler | ||
break; | ||
default: | ||
throw new InvalidCastException($"The exception policy {plugin.ExceptionPolicy} is not valid."); | ||
throw new InvalidCastException( | ||
$"The exception policy {plugin.ExceptionPolicy} is not valid."); | ||
} | ||
|
||
Utility.Log(nameof(plugin), LogLevel.Error, ex); | ||
} | ||
catch (Exception ex) | ||
{ | ||
exceptions.Add(ex); | ||
} | ||
})).ToList(); | ||
|
||
await Task.WhenAll(tasks); | ||
|
||
exceptions.ForEach(e => throw e); | ||
} | ||
} | ||
|
||
/// <summary> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we have this requirement added?