xZetsubou / hass-localtuya

🔹 A Home Assistant integration to handle Tuya devices locally "fork from localtuya"

Home Page:https://xzetsubou.github.io/hass-localtuya/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

pickonedev opened this issue · comments

LocalTuya Version

2024.5.0

Home Assistant Version

2024.5.5

Environment

  • Does the device work using the Home Assistant Tuya Cloud component?
  • Is this device connected to another local integration, including Home Assistant and any other tools?
  • The devices are within the same HA subnet, and they get discovered automatically when I add them

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

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

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.

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

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

Oh, nice, thank you very much.

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

And restart HA then re-add your device

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.

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.

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

image
image

Reverted back to 3.2.5.1

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

This issue was closed because it was resolved on the release: 2024.7.0