bytedreamer / OSDP.Net

A .NET Core control panel implementation of the Open Supervised Device Protocol(OSDP)
Apache License 2.0
47 stars 19 forks source link

OutOfMemoryException when polling #99

Closed mikaelj closed 2 years ago

mikaelj commented 2 years ago

Polling one device over virtual USB-serial. Not using a secure channel. What other information do you need?


OSDP.Net.ControlPanel: Error: Error while sending command OSDP.Net.Messages.PollCommand to address 1. Connection 559491fb-e2f7-4964-a7c4-c39869143562

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Collections.Generic.List`1.set_Capacity(Int32 value)
   at System.Collections.Generic.List`1.EnsureCapacity(Int32 min)
   at System.Collections.Generic.List`1.Insert(Int32 index, T item)
   at System.Collections.ObjectModel.Collection`1.InsertItem(Int32 index, T item)
   at System.Collections.ObjectModel.Collection`1.Add(T item)
   at OSDP.Net.Bus.<WaitForRestOfMessage>d__48.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at OSDP.Net.Bus.<ReceiveReply>d__46.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at OSDP.Net.Bus.<SendCommandAndReceiveReply>d__45.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
bytedreamer commented 2 years ago

Not sure how you were able to exceed the capacity of a collection while receiving reply data. What kind of device is the OSDP.Net running?

Are you able to run the library using a debugger? If so, when the error occurs check the size of the replyBuffer collection in the WaitForRestOfMessage method in the Bus class. Double checking the logic, I don't see how it can exceed the max size of a ushort (65,535)

mikaelj commented 2 years ago

I agree it sounds strange - it shouldn't overflow. According to my OSDP library (ARM Cortex-M3 device) message lengths are between 64 and 110 bytes, and the library I'm using on my end has been in production use for many years. The only new thing is USB CDC ACM...


I'd be happy to try to debug it.

However, I'm a bit of a newbie in Windows development - is there a way i can install a debuggable version of OSDP.Net using the package manager? If not, what's the recommended way?

bytedreamer commented 2 years ago

Not sure if this is the best way...

I switch the reference in the project from the Nuget package to a compiled version of the source code.

bytedreamer commented 2 years ago

Also, are you using the latest version of the Nuget package?

mikaelj commented 2 years ago

nuget package version 3.0.1.

I'll add the project source code to my own temporarily then. Thanks.

mikaelj commented 2 years ago

Can no longer reproduce. I think the error is on my part. Closing.