LAB02-Research / HASS.Agent

Windows-based client for Home Assistant. Provides notifications, quick actions, commands, sensors and more.
https://hassagent.lab02-research.org
MIT License
1.6k stars 74 forks source link

Bug: Crash with FirstChanceException: Unable to read data from the transport connection #338

Open duoduo-x opened 1 year ago

duoduo-x commented 1 year ago

Describe the bug The application crashes quite often with an exception in it's log.

To Reproduce Steps to reproduce the behavior:

  1. run the application
  2. wait for a short period of time
  3. it crashes
  4. Check the log which shows the exception

Expected behavior No Crash

Screenshots No screenshot

Misc info (please complete the following information):

Please check what's applicable (multiple answers possible):

Additional context NA

Logs 2023-08-03 00:33:16.364 -04:00 [INF] [MAIN] HASS.Agent version: 2022.14.0 2023-08-03 00:33:16.366 -04:00 [INF] [MAIN] Extended logging enabled 2023-08-03 00:33:16.369 -04:00 [INF] [SETTINGS] Config storage path: C:\Users\DuoDuo\AppData\Roaming\LAB02 Research\HASS.Agent\config 2023-08-03 00:33:16.462 -04:00 [INF] [SETTINGS] Configuration loaded 2023-08-03 00:33:16.465 -04:00 [INF] [LOCALIZATION] Selected UI culture: [en] English 2023-08-03 00:33:16.650 -04:00 [INF] [SETTINGS_QUICKACTIONS] Config not found, no entities loaded 2023-08-03 00:33:16.651 -04:00 [INF] [SETTINGS_COMMANDS] Config not found, no entities loaded 2023-08-03 00:33:21.601 -04:00 [INF] [SETTINGS_SENSORS] Loaded 4 entities 2023-08-03 00:33:21.605 -04:00 [INF] [LOCALAPI] Disabled 2023-08-03 00:33:21.607 -04:00 [INF] [MQTT] Identifying as device: DESKTOP-Windows 2023-08-03 00:33:21.608 -04:00 [INF] [SERVICE] Local install path: C:\Program Files (x86)\LAB02 Research\HASS.Agent Satellite Service\ 2023-08-03 00:33:21.611 -04:00 [INF] [HOTKEY] Completed bind for global quickaction hotkey 2023-08-03 00:33:21.612 -04:00 [INF] [MQTT] Connecting .. 2023-08-03 00:33:21.628 -04:00 [INF] [MEDIA] Disabled 2023-08-03 00:33:21.654 -04:00 [INF] [MQTT] Connected 2023-08-03 00:33:21.658 -04:00 [INF] [HASS_API] Home Assistant version: 2023.8.0 2023-08-03 00:33:21.683 -04:00 [INF] [NOTIFIER] Ready 2023-08-03 00:33:21.738 -04:00 [INF] [HASS_API] System connected with http://homeassistant.local:8123 2023-08-03 00:33:23.621 -04:00 [INF] [MQTT] Initial registration completed 2023-08-03 00:35:36.718 -04:00 [FTL] [PROGRAM] FirstChanceException: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request.. System.IO.IOException: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request.. ---> System.Net.Sockets.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request. --- End of inner exception stack trace --- at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.Security.SslStream.ReadAsyncInternal[TIOAdapter](TIOAdapter adapter, Memory`1 buffer)

amadeo-alex commented 1 year ago

Hello,

Does the crash happen when there are no sensor/command configured? Is it possible that the crash is happening when any notification action would occur?

ostracizado commented 1 year ago

Exit Hass.Agent if it hasn't crashed yet...

Go to UserName/AppData/Roaming/LAB02 Research/HASS.Agent/config - and rename sensors.json to something else, ex: sensors_off.json.

Then start Hass.Agent and see if there's any kind of crash.

duoduo-x commented 1 year ago

Hello,

Does the crash happen when there are no sensor/command configured? Is it possible that the crash is happening when any notification action would occur?

There are some configured sensors, but no command. No, no notification was ever triggered.

duoduo-x commented 1 year ago

Exit Hass.Agent if it hasn't crash yet...

Go to UserName/AppData/Roaming/LAB02 Research/HASS.Agent/config - and rename sensors.json to something else, ex: sensors_off.jason.

Then start Hass.Agent and see if there's any kind of crash.

Well.. yes, there is no crash any longer. But all configured sensors are gone.

ostracizado commented 1 year ago

Exit Hass.Agent if it hasn't crash yet... Go to UserName/AppData/Roaming/LAB02 Research/HASS.Agent/config - and rename sensors.json to something else, ex: sensors_off.jason. Then start Hass.Agent and see if there's any kind of crash.

Well.. yes, there is no crash any longer. But all configured sensors are gone.

But now you know where's the problem.

Did you change something recently? Hardware, for instance?

In json you can't comment as in yaml, with #"...".# So the only alternative I can think of is to duplicate the file "sensors.json" and save it somewhere else.

Then: 1) Exit Hass.Agent. 2) Return to the config folder, rename once again the "sensors_off.json" (or whatever you name it) to "sensors.json". 3) Delete sensor, one by one, and save every time. 4) Restart Hass.Agent, until you find the one sensor that creates the crash.

duoduo-x commented 1 year ago

Exit Hass.Agent if it hasn't crash yet... Go to UserName/AppData/Roaming/LAB02 Research/HASS.Agent/config - and rename sensors.json to something else, ex: sensors_off.jason. Then start Hass.Agent and see if there's any kind of crash.

Well.. yes, there is no crash any longer. But all configured sensors are gone.

But now you know where's the problem.

Did you change something recently? Hardware, for instance?

In json you can't comment as in yaml, with #"...".# So the only alternative I can think of is to duplicate the file "sensors.json" and save it somewhere else.

Then:

  1. Exit Hass.Agent.
  2. Return to the config folder, rename once again the "sensors_off.json" (or whatever you name it) to "sensors.json".
  3. Delete sensor, one by one, and save every time.
  4. Restart Hass.Agent, until you find the one sensor that creates the crash.

Thanks! I have done what you suggested. It turned out the GPU load sensor is the evil one. but why is that? I previously did not modify anything manually in the sensors.conf file. All sensors in this file were created from the GUI including the GPU one. Maybe it is something worth to investigate? { "Type": "GpuLoadSensor", "Id": "8612cc9b-007a-4c46-ad6b-37e66e5716d8", "UpdateInterval": 30, "Query": "", "Scope": null, "WindowName": "", "Category": "", "Counter": "", "Instance": "", "Name": "DESKTOP-Windows_gpuload" },

ostracizado commented 1 year ago

Thanks! I have done what you suggested. It turned out the GPU load sensor is the evil one. but why is that? I previously did not modify anything manually in the sensors.conf file. All sensors in this file were created from the GUI including the GPU one. Maybe it is something worth to investigate? { "Type": "GpuLoadSensor", "Id": "8612cc9b-007a-4c46-ad6b-37e66e5716d8", "UpdateInterval": 30, "Query": "", "Scope": null, "WindowName": "", "Category": "", "Counter": "", "Instance": "", "Name": "DESKTOP-Windows_gpuload" },

:shrug:

One alternative is to have, for exemple, Open Hardware Monitor. Then in Hass.Agent create a WMI Query's sensor. See Documentation.

Give it the name you want; ex: PC_wmiquery_GPU_Load Add the WMI Query as: SELECT value FROM Sensor WHERE Name LIKE "%GPU Core%" AND SensorType = "Load" And the WMI Scope as: \.\ROOT\OpenHardwareMonitor

You could try other software. WMI Explorer should help with that... Kind of like MQTT Explorer. Oh, and don't forget that the value will be without a unit (%); so you will have to create a sensor/template:

Something like:

      - name: "PC - GPU Load"
        unique_id: pc_gpu_load
        state: >
         {{states('sensor.pc_wmiquery_gpu_load')}}
        unit_of_measurement: "%"

And use that entity for your data collection.

duoduo-x commented 1 year ago

Thanks for the workaround. GPU load is not important to me. So I will just simply keep it away from my configutration for now.