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

[InvalidOperationException] NeoSystem 3.5.0 on Akka #2857

Closed
cschuchardt88 opened this issue Apr 1, 2023 · 2 comments
Closed

[InvalidOperationException] NeoSystem 3.5.0 on Akka #2857

cschuchardt88 opened this issue Apr 1, 2023 · 2 comments

Comments

@cschuchardt88
Copy link
Member

Describe the bug
I have my own custom console app that is using the Class NeoSystem. When i'm importing blocks; I ctrl+C to shutdown the app, while its processing the blocks. When i do so i get the error below. The way i import blocks is the same way you do it in the neo-cli source.
This isn't really a big problem for me. Doesn't affect anything for me. Just thought you should know.

System.InvalidOperationException: Cannot create child while terminating or terminated
   at Akka.Actor.ActorCell.MakeChild(Props props, String name, Boolean async, Boolean systemService)
   at Akka.Actor.ActorCell.AttachChild(Props props, Boolean isSystemService, String name)
   at Akka.Actor.Internal.ActorSystemImpl.SystemActorOf(Props props, String name)
   at Akka.Actor.Inbox.Create(ActorSystem system)
   at Neo.NeoSystem.EnsureStopped(IActorRef actor)
   at Neo.NeoSystem.Dispose()

To Reproduce
Steps to reproduce the behavior:

        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _neosystem ??= new NeoSystem(_protocolsettings, Settings.Current.Storage.Engine, string.Format(Settings.Current.Storage.Path, _protocolsettings.Network.ToString("X8")));

            LocalNode = _neosystem.LocalNode.Ask<LocalNode>(new LocalNode.GetInstance(), cancellationToken: cancellationToken).Result;
            _logger.LogInformation("Neo system local node created.");

            var cancel = new CancellationTokenSource();

            _cancelbroadcast ??= new();

            _braodcastpingtask = Task.Run(async () => await Broadcast(_cancelbroadcast), cancellationToken);
            Task showStateTask = Task.Run(async () => await ShowState(cancel), cancellationToken);

            using (IEnumerator<Block> blocksBeingImported = GetBlocksFromFile().GetEnumerator())
            {
                while (true)
                {
                    List<Block> blocksToImport = new();
                    for (int i = 0; i < 10; i++)
                    {
                        if (!blocksBeingImported.MoveNext()) break;
                        blocksToImport.Add(blocksBeingImported.Current);
                    }
                    if (blocksToImport.Count == 0) break;
                    await _neosystem.Blockchain.Ask<Blockchain.ImportCompleted>(new Blockchain.Import
                    {
                        Blocks = blocksToImport,
                        Verify = true,
                    }, cancellationToken: cancellationToken);
                    if (_neosystem is null) return;
                }
            }
            cancel.Cancel();
            try { showStateTask.Wait(cancellationToken); } catch { }
            _logger.LogInformation("Neo system import completed.");

            _neosystem.StartNode(new ChannelsConfig
            {
                Tcp = new IPEndPoint(IPAddress.Any, Settings.Current.P2P.Port),
                WebSocket = new IPEndPoint(IPAddress.Any, Settings.Current.P2P.WsPort),
                MinDesiredConnections = Settings.Current.P2P.MinDesiredConnections,
                MaxConnections = Settings.Current.P2P.MaxConnections,
                MaxConnectionsPerAddress = Settings.Current.P2P.MaxConnectionsPerAddress
            });

            _logger.LogInformation("Neo system node started.");
        }

        public Task StopAsync(CancellationToken cancellationToken)
        {
            _cancelbroadcast?.Cancel();
            try { _braodcastpingtask.Wait(cancellationToken); } catch { }
            _cancelbroadcast?.Dispose();
            _neosystem?.Dispose();
            _cancelbroadcast = null;
            _neosystem = null;
            return Task.CompletedTask;
        }

Expected behavior
The "Neo.NeoSystem.EnsureStopped(IActorRef actor)" function check for application terminating or terminated and handle it by shutting down the Akka. Seeing how the neo-cli is a console app the problem could come up down the road(in future release).

Screenshots
image

Platform:

  • OS: Windows 10 Pro x64 21H2 19044.2728 (Windows Feature Experience Pack 120.2212.4190.0)
  • Version Neo 3.5.0, Dotnet 7.0.202
@ixje
Copy link
Contributor

ixje commented Apr 18, 2023

I expect this to be solved by #2842 which is planned for 3.6.0

@cschuchardt88
Copy link
Member Author

cschuchardt88 commented Nov 9, 2023

looks like it is fixed. At least it was merged.

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