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

Occasional Unhandled Exceptions #142

Closed
elcosmelco opened this issue May 9, 2018 · 1 comment
Closed

Occasional Unhandled Exceptions #142

elcosmelco opened this issue May 9, 2018 · 1 comment

Comments

@elcosmelco
Copy link

I am using the client in a Xamarin Forms project on an Android 8.0 device and about 70% of the time things run as expected. The other 30% of the times I launch the app it crashes immediately with an unhandled exception stating "An item with the same key has already been added. Key: System.Net.Mqtt.Sdk.Storage.RetainedMessage". I've tried try/catch on everything to do with the client object and it doesn't catch it.

The call stack is as following:
at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException (System.Object key) [0x00006] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at System.Collections.Generic.Dictionary'2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x000ad] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at System.Collections.Generic.Dictionary'2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at System.Net.Mqtt.Sdk.Storage.InMemoryRepositoryProvider.GetRepository[T] () [0x0006a] in C:\Code\Xamarin\mqtt\src\Client\Sdk\Storage\InMemoryRepositoryProvider.cs:24 at System.Net.Mqtt.Sdk.Flows.ClientProtocolFlowProvider.InitializeFlows () [0x00012] in C:\Code\Xamarin\mqtt\src\Client\Sdk\Flows\ClientProtocolFlowProvider.cs:21 at System.Net.Mqtt.Sdk.Flows.ProtocolFlowProvider.GetFlows () [0x00008] in C:\Code\Xamarin\mqtt\src\Client\Sdk\Flows\ProtocolFlowProvider.cs:64 at System.Net.Mqtt.Sdk.Flows.ProtocolFlowProvider.GetFlow (System.Net.Mqtt.Sdk.Packets.MqttPacketType packetType) [0x0002a] in C:\Code\Xamarin\mqtt\src\Client\Sdk\Flows\ProtocolFlowProvider.cs:40 at System.Net.Mqtt.Sdk.ClientPacketListener+<DispatchPacketAsync>d__23.MoveNext () [0x0002a] in C:\Code\Xamarin\mqtt\src\Client\Sdk\ClientPacketListener.cs:194 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at System.Net.Mqtt.Sdk.ClientPacketListener+<<ListenNextPackets>b__17_0>d.MoveNext () [0x0002c] in C:\Code\Xamarin\mqtt\src\Client\Sdk\ClientPacketListener.cs:108 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_1 (System.Object state) [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) [0x00007] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00021] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0

Cheers,
Elco

mauroa added a commit that referenced this issue May 29, 2018
- Without the concurrency control it could happen that the flows are initialized in parallel, causing a duplicate key exception on the flows dictionary to be thrown
- Yhis fixes GitHub Issue "Occasional Unhandled Exceptions #142": #142
mauroa added a commit that referenced this issue May 29, 2018
- Without the concurrency control it could happen that the flows are initialized in parallel, causing a duplicate key exception on the flows dictionary to be thrown
- Yhis fixes GitHub Issue "Occasional Unhandled Exceptions #142": #142
@mauroa
Copy link
Contributor

mauroa commented Jun 1, 2018

This has already been addressed in the recent commits and it will be available in the next release coming soon. Closing this issue.

@mauroa mauroa closed this as completed Jun 1, 2018
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