Skip to content
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

IPersistencePlugin May Lose Data Because of the Disposing Order in NeoSystem.cs #2624

Closed
dusmart opened this issue Nov 8, 2021 · 1 comment

Comments

@dusmart
Copy link

dusmart commented Nov 8, 2021

Describe the bug
When we shut down the neo-node by Ctrl-C or exit command or any other unexpected method, we will probably lose one block's data for every IPersistencePlugin if it's syncing block and using OnCommit() for data recording. If OnPersist() is used for data recording, no data will be lost while an exception will be thrown.

Background
We're trying to build an archive node by adding an IPersistencePlugin that records all data at any block height. When we add the Dispose method, the DB will always meet a segmentation fault when we stop the neo-node.

To Reproduce
Steps to reproduce the behavior:

  1. Open the neo-node, install any IPersistencePlugin with Dispose() method that releases the essential resouces.
  2. Run ./neo-node
  3. Type exit after it starts syncing block

Expected behavior
The plugin will cause an exception because of using resources after releasing them.

Screenshots

   at Neo.Plugins.Storage.Store.Put(Byte[] key, Byte[] value)
   at Neo.Plugins.ArchiveStore.<>c__DisplayClass3_0.<OnPersist>b__0(Trackable v)
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at Neo.Plugins.ArchiveStore.OnPersist(NeoSystem ns, Block block, DataCache snapshot, IReadOnlyList`1 ae)
   at Neo.Ledger.Blockchain.Persist(Block block)
   at Neo.Ledger.Blockchain.OnImport(IEnumerable`1 blocks, Boolean verify)
   at Akka.Actor.UntypedActor.Receive(Object message)
   at Akka.Actor.ActorBase.AroundReceive(Receive receive, Object message)
   at Akka.Actor.ActorCell.ReceiveMessage(Object message)
   at Akka.Actor.ActorCell.Invoke(Envelope envelope)
   at Akka.Dispatch.Mailbox.ProcessMailbox(Int32 left, Int64 deadlineTicks)
   at Akka.Dispatch.Mailbox.ProcessMailbox()
   at Akka.Dispatch.Mailbox.<Run>b__36_0()
   at Akka.Actor.ActorCell.UseThreadContext(Action action)
   at Akka.Dispatch.Mailbox.Run()
   at Akka.Dispatch.ThreadPoolExecutorService.<>c.<.cctor>b__3_0(Object t)
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

[1]    56384 segmentation fault  ./neo-cli

neo/src/neo/NeoSystem.cs

Lines 164 to 174 in d092510

public void Dispose()
{
foreach (var p in Plugin.Plugins)
p.Dispose();
EnsureStoped(LocalNode);
// Dispose will call ActorSystem.Terminate()
ActorSystem.Dispose();
ActorSystem.WhenTerminated.Wait();
HeaderCache.Dispose();
store.Dispose();
}

Expected code
Move EnsureStoped(LocalNode); before plugins' Dispose().
At least make sure all IPersistencePlugins dispose after the LocalNode is stoped.

Maybe ApplicationLogs Plugin can add the Dispose() method to release DB safely after this issue is solved.

@Qiao-Jin
Copy link
Contributor

Qiao-Jin commented Nov 9, 2021

Similiar issues and PRs which might be usedful for this problem:
#2570
neo-project/neo-node#816

#2576

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants