HomeAssistant-RoboVac icon indicating copy to clipboard operation
HomeAssistant-RoboVac copied to clipboard

Transport Endpoint is Already Connected

Open BnMcG opened this issue 5 years ago • 19 comments

Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/entity.py", line 220, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/app/homeassistant/helpers/entity.py", line 375, in async_device_update
    await self.async_update()
  File "/config/custom_components/eufyrobovac/vacuum.py", line 173, in async_update
    state = self.vacuum.get_status()
  File "/config/deps/lib/python3.7/site-packages/robovac/robovac.py", line 157, in get_status
    message = self._build_get_device_status_user_data_message()
  File "/config/deps/lib/python3.7/site-packages/robovac/robovac.py", line 284, in _build_get_device_status_user_data_message
    magic_number = self._get_magic_number()
  File "/config/deps/lib/python3.7/site-packages/robovac/robovac.py", line 300, in _get_magic_number
    pong = self._send_packet(ping, True)
  File "/config/deps/lib/python3.7/site-packages/robovac/robovac.py", line 318, in _send_packet
    self.connect()
  File "/config/deps/lib/python3.7/site-packages/robovac/robovac.py", line 153, in connect
    self.s.connect((self.ip, self.port))
OSError: [Errno 106] Transport endpoint is already connected

BnMcG avatar May 29 '19 12:05 BnMcG

I too am getting this error now after months of working fine. Any ideas?

Wed Jul 17 2019 23:03:39 GMT-0400 (Eastern Daylight Time) Failed to update RoboVac status: [Errno 106] Transport endpoint is already connected Connection lost. Reconnecting…

codypet avatar Jul 18 '19 03:07 codypet

Have you tried restarting Home Assistant and the Robovac? I think that's how I "fixed" this when it happened to me, I'll take a look at making the code a bit more robust.

BnMcG avatar Jul 18 '19 10:07 BnMcG

Yea I restarted it because in the past, that's historically fixed the problem. Then I assumed maybe the Robovac wasn't connecting to the server, but that's not the problem either. I don't have any other errors so this one is a head scratcher for me.

codypet avatar Jul 18 '19 11:07 codypet

What version of Home Assistant are you using?

BnMcG avatar Jul 18 '19 15:07 BnMcG

0.95.4 right now, and it's been working fine for the last few weeks. I'm wondering if it's related to something Eufy did. I didn't go to 0.96.0 yet.

codypet avatar Jul 18 '19 18:07 codypet

OK - don't upgrade to 0.96.0 quite yet - there's some sort of bug either in this package or Home Assistant itself where it doesn't correctly download the required Python module in 0.96.0, but this doesn't happen in 0.95.4.

I've been looking at that bug today and I can confirm that HA 0.95.4 works fine for me locally using the Robovac component, so it shouldn't be any changes Eufy have made unless your Robovac has received an update mine hasn't for some reason.

Just to clarify, have you restarted both Home Assistant and the Robovac?

BnMcG avatar Jul 18 '19 18:07 BnMcG

Yes, I have but will try it again when I get home from work in case it was something going on with my machine last night.

codypet avatar Jul 18 '19 19:07 codypet

How are you running Home Assistant, by the way? As far as I know this error should be transient and not persist across reboots, as I think it's to do with a socket already being in use.

BnMcG avatar Jul 18 '19 19:07 BnMcG

Hassbian on a Raspberry Pi3 running Python 3.7.3.

codypet avatar Jul 18 '19 19:07 codypet

I went back and verified that my Eufy was connected to the right wifi router, and not the repeater, at the correct IP address, restarted it, and rebooted the whole pi. Still the same issue. Its bizarre because this hasn't been a problem since you refreshed the layout about a month ago until now. More Errors: (Hadn't seen this 2 bytes one before) Thu Jul 18 2019 22:49:04 GMT-0400 (Eastern Daylight Time) Failed to update RoboVac status: unpack requires a buffer of 2 bytes Thu Jul 18 2019 22:51:51 GMT-0400 (Eastern Daylight Time) Failed to update RoboVac status: [Errno 106] Transport endpoint is already connected

codypet avatar Jul 19 '19 02:07 codypet

OK, I've taken a closer look at the error and it's a problem in the underlying Python library that communicates with the Robovac, not a problem with Home Assistant or the custom component.

The code is written such that it tries to send the instruction to the Robovac, and if that fails for whatever reason, there's a catch-all where it will then try to connect to the Robovac and then send the instruction again. I think what's happening is that sending the packet is failing for other reasons, the catch-all is triggered, it tries to reconnect, and then that fails because the connection already exists.

I'll see if I can narrow down which exceptions are thrown in order to better handle errors.

BnMcG avatar Jul 19 '19 08:07 BnMcG

I've tagged a v0.1.2 release of the custom component - this uses the 0.0.9 version of the PyRobovac library that I just released, which has slightly more robust error handling and better logging of the actual exceptions that occurred.

Can you try upgrading the custom component for me, restarting Home Assistant and seeing how you get on? I don't think there's a reliable way to reproduce this so it might just be a case of waiting and seeing if the transport error comes back.

If you could periodically skim through your logs and see if any exceptions are logged relating to connecting to the Robovac, that'd be great as well - it'd be good to know what's causing the communication to fail.

The buffer error you posted will occur when the Robovac sends back some data that's not in the format the library expects. I've not exactly worked out when this happens, but it does occur once in a while - I think it may be sending back some sort of error, but that's just a guess.

BnMcG avatar Jul 19 '19 08:07 BnMcG

image Alright. Now we have some errors. I don't know what a file descriptor or a pipe is though. Fri Jul 19 2019 23:07:33 GMT-0400 (Eastern Daylight Time) Failed to update RoboVac status: unpack requires a buffer of 2 bytes Fri Jul 19 2019 23:07:54 GMT-0400 (Eastern Daylight Time) [Errno 32] Broken pipe Traceback (most recent call last): File "/srv/homeassistant/lib/python3.7/site-packages/robovac/robovac.py", line 324, in _send_packet self.s.send(encrypted_packet_data) BrokenPipeError: [Errno 32] Broken pipe Fri Jul 19 2019 23:10:00 GMT-0400 (Eastern Daylight Time) [Errno 9] Bad file descriptor Traceback (most recent call last): File "/srv/homeassistant/lib/python3.7/site-packages/robovac/robovac.py", line 324, in _send_packet self.s.send(encrypted_packet_data) OSError: [Errno 9] Bad file descriptor Fri Jul 19 2019 23:10:00 GMT-0400 (Eastern Daylight Time) Failed to update RoboVac status: [Errno 9] Bad file descriptor

codypet avatar Jul 20 '19 03:07 codypet

The file descriptor errors are to do with a bug I introduced in the underlying library while fixing the transport errors - I think I have a fix for it I'll push out this morning. Once that's fixed you may still see the broken pipe errors but I don't think they'll impact the functionality.

BnMcG avatar Jul 20 '19 11:07 BnMcG

Ok restarting HA today and I lost the Eufy altogether and I think I know what part of the problem is. When I log into my wifi router there's no Eufy. Not in the IP I have reserved for it, not anywhere. Eufy in the app still says its connected to my wifi router, and still works in the app. I don't know why its not showing up in the router settings. I suspect with that missing, the HA configuration doesn't see it either and therefore that's why its not working in HA. I just.....don't know why the router says the Eufy isn't there.

codypet avatar Jul 21 '19 20:07 codypet

Might just be the router interface, have you tried pinging the Vac from the command line? If it’s still showing connected on the app it must be there somewhere..

JXGA avatar Jul 21 '19 20:07 JXGA

So when I ping, something is reporting back right away so....I don't know what's going on.

codypet avatar Jul 21 '19 20:07 codypet

So Eufy started showing back up in my router again at the proper IP address, matching the login information and it still doesn't show up and it still gives me the same errors. How is everyone faring with 0.96?

codypet avatar Jul 26 '19 02:07 codypet

There is an update coming to the underlying module that serves this custom_component, hopefully won't be long until it's released. It will still give an occasional error in the logs, but seems to work okay.

JXGA avatar Jul 26 '19 09:07 JXGA