xZetsubou / hass-localtuya

🔹 A Home Assistant integration to handle Tuya devices locally "fork from localtuya"
https://xzetsubou.github.io/hass-localtuya/
GNU General Public License v3.0
287 stars 30 forks source link

[Bug]: socket.send() raised exception after new update #256

Open pickonedev opened 1 month ago

pickonedev commented 1 month ago

LocalTuya Version

2024.5.0

Home Assistant Version

2024.5.5

Environment

What happened?

A bug happened!

After I updated to the new version, I got more than 7000 warnings in less than 30 minutes...

Logger: asyncio
Source: custom_components/localtuya/core/pytuya/__init__.py:979
integration: LocalTuya ([documentation](https://github.com/xZetsubou/hass-localtuya/), [issues](https://github.com/xZetsubou/hass-localtuya/issues))
First occurred: 23:14:02 (7437 occurrences)
Last logged: 23:37:44
socket.send() raised exception.

Steps to reproduce.

Update to 2024.5.0 and watch logs after reboot of HA

Relevant log output

No response

Diagnostics information.

No response

Possible Workaround

Downgrading to 3.2.5.1, no issue in the log

pickonedev commented 1 month ago

Oh, and another different occurrances, if helps:

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/localtuya/core/pytuya/__init__.py:611
integration: LocalTuya (documentation, issues)
First occurred: 23:15:48 (303 occurrences)
Last logged: 23:40:25

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 520, in wait_for
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/locks.py", line 386, in acquire
    await fut
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 606, in wait_for
    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 519, in wait_for
    async with timeouts.timeout(timeout):
  File "/usr/local/lib/python3.12/asyncio/timeouts.py", line 115, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/localtuya/coordinator.py", line 395, in _async_refresh
    await self._interface.update_dps(cid=self._node_id)
  File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 1136, in update_dps
    await self.detect_available_dps(cid=cid)
  File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 1187, in detect_available_dps
    data = await self.status(cid=cid)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 1098, in status
    status: dict = await self.exchange(command=DP_QUERY, nodeID=cid, delay=False)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 1072, in exchange
    msg = await self.dispatcher.wait_for(seqno, payload.cmd)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 611, in wait_for
    del self.listeners[seqno]
        ~~~~~~~~~~~~~~^^^^^^^
KeyError: 14295
pickonedev commented 1 month ago

I tried again, but the same issue. I will stai with the downgraded version till the problem will be solved. If I let the new update, after 30.000 occurrances, HA it is starting to response slower and slower to any command.

pickonedev commented 3 weeks ago

@xZetsubou Hi! Sorry to bother you, but do you have any idea about the issue I have?

xZetsubou commented 3 weeks ago

I made changes for this I haven't pushed it on GitHub yet because I'm still testing it, I'll push it probably today and you can test it by installing master or I may release beta fix

pickonedev commented 3 weeks ago

Oh, nice, thank you very much.

xZetsubou commented 3 weeks ago

I pushed the change to make sure that it fixed the issue for you can you test the latest master version.

Install Master Version

Go HACS -> Local Tuya -> On top right corner click on the ⋮ and choose redownload and select master ![image](https://github.com/xZetsubou/hass-localtuya/assets/46300268/e326b0b6-74cf-49e0-9696-3b444178083b) And restart HA then re-add your device

Cycor commented 2 weeks ago

I am also getting this error and it still occurs in the master build, I have to restart my home assistant or it stops responding:

Logger: asyncio Source: custom_components/localtuya/core/pytuya/init.py:992 integration: LocalTuya (documentation, issues) First occurred: 09:12:48 (475098 occurrences) Last logged: 11:14:52

socket.send() raised exception.


This is right before it starts spamming:

2024-06-12 09:12:46.913 WARNING (SyncWorker_42) [custom_components.localtuya.coordinator] [bff...we4 - Smart Energy Meter] Disconnected: waiting for discovery broadcast 2024-06-12 09:12:48.399 WARNING (MainThread) [asyncio] socket.send() raised exception. 2024-06-12 09:12:48.402 WARNING (MainThread) [asyncio] socket.send() raised exception. 2024-06-12 09:12:58.367 WARNING (MainThread) [asyncio] socket.send() raised exception. 2024-06-12 09:12:58.442 WARNING (MainThread) [asyncio] socket.send() raised exception. 2024-06-12 09:12:58.505 WARNING (MainThread) [asyncio] socket.send() raised exception. 2024-06-12 09:12:58.566 WARNING (MainThread) [asyncio] socket.send() raised exception. 2024-06-12 09:12:58.629 WARNING (MainThread) [asyncio] socket.send() raised exception. 2024-06-12 09:13:03.194 WARNING (MainThread) [asyncio] socket.send() raised exception.

xZetsubou commented 2 weeks ago

I am also getting this error and it still occurs in the master build, I have to restart my home assistant or it stops responding:

I think it will be fixed in next releases however I don't know what exactly causing it but I kinda have an idea.

pickonedev commented 2 weeks ago

With the new version "2024.6.0", it is the same or even worst...

image image

Reverted back to 3.2.5.1

pickonedev commented 1 week ago

@xZetsubou if you need any help in testing other master version, please tell me. This issue it is very annoying. Thanks