This unobserved exception comes sometimes and results in confusion, I just discovered what we have to do with it. NBitcoin's Node has a Node.UncaughtException event. We must subscribe and handle/log/etc...
2019-11-17 13:37:57 WARNING Program (89) System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (The peer has been disconnected) ---> System.OperationCanceledException: The peer has been disconnected
--- End of inner exception stack trace ---
---> (Inner Exception #0) System.OperationCanceledException: The peer has been disconnected<---
Should this be closed?
No, we only catch it in a single place, not everywhere.
I was working on this for two hours more or less and I was not able to catch this exception. I tried subscribing to the Node.UncaughtException event in the AddressManagerBehavior.AttachCore (and unsibscribe in AddressManagerBehavior.DetachCore but it doesn't work, it seems the event is not rise.
I was just trying dotnet run -- mix --wallet:Test --destination:Daemon-nopass command and I see this:
2020-03-19 20:20:09 WARNING Program (80) System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (The peer has been disconnected)
---> System.OperationCanceledException: The peer has been disconnected
--- End of inner exception stack trace ---
Well, my theory was proved to be incorrect. Reopening.