DarthAffe / OBD.NET

C#-Library to read data from car through an ELM327-/STN1170-Adapter
GNU General Public License v2.0
178 stars 82 forks source link

Fix deadlock on connection lost #24

Closed MB512 closed 2 years ago

MB512 commented 2 years ago

When connection is lost after the command was send there was no possibility to dispose the Device.

This fix uses a timeout in the WaitOne call and checks the Cancellation token. Additionally it notifies all commands that they are finished (with null response).

This makes it possible to dispose a Device if a command was send but the connection is lost before the response is received.

DarthAffe commented 2 years ago

Oh that's a great find - I was seeing issues with capturing data getting stuck myself from time to time, but could never really track it down

MB512 commented 2 years ago

Thanks! I just want to add that this just adds the possibility to dispose the Device in this case. One could add a CommandTimeout property and handle it at the same location, but I didn't want to change to much.

I am using this by starting a watchdog timer with every command send to the Device, stopping it after the command finished and when fired I dispose the Device and recreate it.