emitter-io / csharp

Client library for emitter.io compatible with .Net, .Net MicroFramework and WinRT
http://emitter.io
Eclipse Public License 1.0
29 stars 21 forks source link

Invalid nested call #27

Open lufinkey opened 2 months ago

lufinkey commented 2 months ago

Randomly when trying to disconnect emitter (on the same thread where Connect was called), I get an exception "Invalid nested call". This is inconsistent and only happens about half the time.

Here is the stack trace:

InvalidOperationException: Invalid nested call.
Mono.Net.Security.MobileAuthenticatedStream.GetInvalidNestedCallException () (at <babece01671744c6913f4a167b091f9e>:0)
Mono.Net.Security.MobileAuthenticatedStream.StartOperation (Mono.Net.Security.MobileAuthenticatedStream+OperationType type, Mono.Net.Security.AsyncProtocolRequest asyncRequest, System.Threading.CancellationToken cancellationToken) (at <babece01671744c6913f4a167b091f9e>:0)
Rethrow as AggregateException: One or more errors occurred. (Invalid nested call.)
System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) (at <bfbc89a04b6b4dd49c3614d03fc31ce8>:0)
System.Threading.Tasks.Task.Wait (System.Int32 millisecondsTimeout, System.Threading.CancellationToken cancellationToken) (at <bfbc89a04b6b4dd49c3614d03fc31ce8>:0)
System.Threading.Tasks.Task.Wait () (at <bfbc89a04b6b4dd49c3614d03fc31ce8>:0)
Mono.Net.Security.MobileAuthenticatedStream.Write (System.Byte[] buffer, System.Int32 offset, System.Int32 count) (at <babece01671744c6913f4a167b091f9e>:0)
System.Net.Security.SslStream.Write (System.Byte[] buffer, System.Int32 offset, System.Int32 count) (at <babece01671744c6913f4a167b091f9e>:0)
Emitter.MqttNetworkChannel.Send (System.Byte[] buffer) (at Assets/Plugins/EmitterIO/Emitter/Emitter/Net/MqttNetworkChannel.cs:302)
Emitter.MqttClient.Send (System.Byte[] msgBytes) (at Assets/Plugins/EmitterIO/Emitter/Emitter/MqttClient.cs:769)
Rethrow as MqttCommunicationException
Emitter.MqttClient.Send (System.Byte[] msgBytes) (at Assets/Plugins/EmitterIO/Emitter/Emitter/MqttClient.cs:780)
Emitter.MqttClient.Send (Emitter.Messages.MqttMsgBase msg) (at Assets/Plugins/EmitterIO/Emitter/Emitter/MqttClient.cs:793)
Emitter.MqttClient.Disconnect () (at Assets/Plugins/EmitterIO/Emitter/Emitter/MqttClient.cs:530)
Emitter.Connection.Disconnect () (at Assets/Plugins/EmitterIO/Emitter/Emitter/Emitter.cs:236)
Florimond commented 2 months ago

Thanks for the report.

I'm not sure I'm going to investigate this particular issue right now as I'm about to write a new version of this lib from scratch. This time it would be based on the very official MQTTNet, which MQTT lib didn't exist at the time we first wrote this Emitter SDK in C#. I think I'm going to try to speed up the writing of this new version instead of fixing the old one...

Since we have you here, would you like to tell us a bit about your use case? Do you have specific needs I could take into account before starting the rewrite?