[ https://issues.apache.org/jira/browse/AMQNET-836?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Pavel Borisov updated AMQNET-836: --------------------------------- Summary: UnobservedTaskException after a failover (was: UnobservedTaskException in the failover) > UnobservedTaskException after a failover > ---------------------------------------- > > Key: AMQNET-836 > URL: https://issues.apache.org/jira/browse/AMQNET-836 > Project: ActiveMQ .Net > Issue Type: Bug > Components: ActiveMQ > Environment: .NET 6 > Reporter: Pavel Borisov > Priority: Major > > When the ActiveMQ instance becomes inaccessible, and the failover happens, > our applications start to report the following error: > _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 actual unobserved error is a SocketException. > The origin of the issue is in > {*}TcpTransportFactory.{*}{*}TryConnectSocket{*} > ([github|https://github.com/apache/activemq-nms-openwire/blob/b89b7498d12fe2f68ee5ee248bb2168c62ceaf3a/src/Transport/Tcp/TcpTransportFactory.cs#L240]). > It starts an async task (socket.BeginConnect), but its result is not > observed. The result is checked by the `socket.Connected` only, and in case > of failure, the actual exception in the task stays unobserved and is > eventually promoted to the UnobservedTaskException event. > Also, for APM methods (Begin*), there are End* methods that *must* be called > according to the docs. But the call to EndConnect is missing in > {*}TryConnectSocket{*}, so a socket stays partially invalid after a > successful connection. > The [snippet > here|https://gist.github.com/Inok/9b17282532bca8a01cc5fc0ab9872433] contains > the same code with some logging, and it reproduces the issue (.NET 6, run in > Release mode). > The fix for both problems is probably [something like > this|https://gist.github.com/Inok/666d647b1bb337bcbef8cad02032237f]. -- This message was sent by Atlassian Jira (v8.20.10#820010)