lukasroegner / homebridge-apple-tv-remote

Plugin for controlling Apple TVs in homebridge.
MIT License
131 stars 13 forks source link

Error: read ECONNRESET #12

Closed Nastras closed 4 years ago

Nastras commented 4 years ago

Hello Lukas,

I'm just trying out a few things with the plugin. I noticed that when the Apple TV is not available and you send a command the Homebridge instance crashes.

Wouldn't it make sense to create a loop where the plugin waits until the Apple TV is available again and displays a message in the Journalctl that the command cannot be sent?

Bildschirmfoto 2020-03-03 um 13 53 36

Best regards Nastra

lukasroegner commented 4 years ago

Have you seen such an issue again with the next version? This should be fixed as the next version always tries to reconnect if commands cannot be sent to the Apple TV.

Nastras commented 4 years ago

I just tested it.

  1. When I unplug Apple TV from power and the plugin instance reboots, it detects that Apple TV is not available. Then I reconnected the Apple TV and shortly after that the plugin crashed.
Bildschirmfoto 2020-03-09 um 07 59 00
  1. plugin instance started and then disconnected Apple TV from the power. Command sent to the Apple TV and plugin does not crash.

But the plugin does not recognize that Apple TV is not available since several minutes?

Nastras commented 4 years ago

I have repeated test 2. and the behaviour is the same. Plugin does not recognize that all tv is disconnected from the stream. When power is restored the plugin crashes.

Bildschirmfoto 2020-03-09 um 08 04 58
lukasroegner commented 4 years ago

Hi @Nastras,

I think I found the issue, I missed some try-catch-logic for errors when sending the heartbeat message to the Apple TV. I published a new version on the next branch (also on NPM with next tag).

Can you check it out?

Nastras commented 4 years ago

I have made the update but unfortunately I can't test it because I will be back home at the weekend. Sorry.

Nastras commented 4 years ago

Today I noticed something else with the first next version. When the Apple TV is embedded in a scene with the state off and the scene is triggered it turns on. But I could not test it extensively.

lukasroegner commented 4 years ago

@Nastras, I added a check if the Apple TV is already on if switched on/is already off if switched off. This prevents actions if the Apple TV is already in the requested state. New version is on NPM.

Nastras commented 4 years ago

Hello Lukas, I finally got a chance to try it out.

@Nastras, I added a check if the Apple TV is already on if switched on/is already off if switched off. This prevents actions if the Apple TV is already in the requested state. New version is on NPM.

It works!

I have repeated test 2. and the behaviour is the same. Plugin does not recognize that all tv is disconnected from the stream. When power is restored the plugin crashes.

The error still exists. But the error is not a problem because the instance restarts automatically. Therefore the question is whether it is worth the effort?

Bildschirmfoto 2020-03-14 um 19 50 01
lukasroegner commented 4 years ago

Hi @Nastras,

I really tried to find all usages of the node-appletv library and surrounded them with try-catch (so that the error is handled by the plugin). Either I missed one or this error occurs on a different "thread" and thus cannot be handled by the plugin.

I made several changes to my homebridge setup, I'm now using separate instances for each plugin and switched over to a Raspberry Pi 4. That should make it easier for me to go through the logs and detect issues with the plugins.

lukasroegner commented 4 years ago

Honestly, I can't find a missing try-catch in the code of the plugin, that's why I assume that the exception is unhandled in a dependency of node-appletv-x. I'll keep an eye on that and update the dependencies as soon as updates are available.