nitaybz / homebridge-network-presence

Homebridge plugin that provides occupancy sensor for devices presence in your network
MIT License
41 stars 6 forks source link

Homebridge fails to start #17

Closed korgoth closed 3 years ago

korgoth commented 3 years ago

I have been using this plugin for about 2 weeks and so far it was working fine.

Today i had to make some tweaks to my RPi (disable wifi and bluetooth) and when i rebooted the RPi - homebridge was not starting anymore. I believe that this plugin is causing the problem since when i disable it - everything works ok. I have tried to revert my change (ie turn wifi and bluetooth back on and reboot the server) - but i homebridge still fails to start when i have anything configured with network presence.

Here is what i see in the log right before it fails:


[12/02/2021, 16:07:27] [Plex Webhooks Platform] Initializing PlexWebhooks platform...
[12/02/2021, 16:07:27] [NetworkPresence] Initializing NetworkPresence platform...
[12/02/2021, 16:07:27] Loading 11 accessories...
[12/02/2021, 16:07:27] [Heater] Initializing broadlinkSP accessory...
[12/02/2021, 16:07:27] [Vacuum] Initializing XiaomiRoborockVacuum accessory...
HAP Warning: Characteristic 000000AC-0000-1000-8000-0026BB765291 not in required or optional characteristics for service 00000040-0000-1000-8000-0026BB765291. Adding anyway.
HAP Warning: Characteristic 000000AB-0000-1000-8000-0026BB765291 not in required or optional characteristics for service 00000040-0000-1000-8000-0026BB765291. Adding anyway.
[12/02/2021, 16:07:27] [Main Light BR] Initializing mqttthing accessory...
[12/02/2021, 16:07:27] [Left light LR] Initializing mqttthing accessory...
[12/02/2021, 16:07:27] [Right Light LR] Initializing mqttthing accessory...
[12/02/2021, 16:07:27] [LR Temp] Initializing mqttthing accessory...
[12/02/2021, 16:07:27] [Bath Light] Initializing mqttthing accessory...
[12/02/2021, 16:07:27] [Bath Fan] Initializing mqttthing accessory...
[12/02/2021, 16:07:27] [Bath Temp] Initializing mqttthing accessory...
[12/02/2021, 16:07:27] [Btn] Initializing mqttthing accessory...
[12/02/2021, 16:07:27] [Guests at home] Initializing DummySwitch accessory...
[12/02/2021, 16:07:27] [Guests at home] Setting switch to false
[12/02/2021, 16:07:27] [homebridge-magichome-dynamic-platform] 1 - Loading accessory from cache... Mood Up
[12/02/2021, 16:07:27] [homebridge-magichome-dynamic-platform] 2 - Loading accessory from cache... Mood Down
[12/02/2021, 16:07:27] [homebridge-magichome-dynamic-platform] 3 - Loading accessory from cache... Bedside
[12/02/2021, 16:07:27] [homebridge-magichome-dynamic-platform] 4 - Loading accessory from cache... Kitchen
[12/02/2021, 16:07:27] [BraviaPlatform] Restoring Livingroom TV from HomeKit
[12/02/2021, 16:07:27] [homebridge-magichome-dynamic-platform] Executed didFinishLaunching callback
[12/02/2021, 16:07:27] [Plex Webhooks Platform] Found 2 accessories in config:
[12/02/2021, 16:07:27] [Plex Webhooks Platform] • Plex Bedroom
[12/02/2021, 16:07:27] [Plex Webhooks Platform] • Plex Livingroom
[12/02/2021, 16:07:28] [Plex Webhooks Platform] Updating accessory [Plex Bedroom] (7d19f28e-63d3-49be-a5a1-afccf0bd7957)
[12/02/2021, 16:07:28] [Plex Webhooks Platform] Updating accessory [Plex Livingroom] (229389f6-f437-4962-ac78-8df444a3f08e)
[12/02/2021, 16:07:28] [NetworkPresence] Initiating Network Scanner...

<--- Last few GCs --->

[755:0x4fc2a38]    34820 ms: Mark-sweep (reduce) 230.3 (233.2) -> 229.9 (233.2) MB, 975.5 / 0.1 ms  (+ 0.5 ms in 159 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 1257 ms) (average mu = 0.284, current mu = 0.282) alloc[755:0x4fc2a38]    36525 ms: Mark-sweep (reduce) 230.4 (231.7) -> 230.0 (232.5) MB, 1701.5 / 0.1 ms  (average mu = 0.163, current mu = 0.002) allocation failure scavenge might not succeed

<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
[12/02/2021, 16:07:58] [HB Supervisor] Homebridge Process Ended. Code: null, Signal: SIGABRT
[12/02/2021, 16:08:03] [HB Supervisor] Restarting Homebridge...

And this goes on in an endless loop. I only had 1 accessory configured + the "Anyone" sensor.

I just can't figure out what might be the cause of that. Does anyone has any idea how to debug any further as from the log i am not getting any useful information so far

korgoth commented 3 years ago

This is the Network presence part of my config - if it helps:

{
    "debug": true,
    "interval": 60,
    "threshold": 15,
    "anyoneSensor": false,
    "devices": [
        {
            "name": "iPhone",
            "ip": "xxx.xxx.xxx.xxx",
            "threshold": 15
        }
    ],
    "platform": "NetworkPresence"
}
nitaybz commented 3 years ago

what raspberry pi are you using?

korgoth commented 3 years ago

Raspberry PI 3B+

Whats - i have added this to /boot/config.txt to disable wifi and bt:

[all] dtoverlay=disable-wifi dtoverlay=disable-bt

But even if i remove it - the behavior is still the same

nitaybz commented 3 years ago

I'm using the exact same device with many other plugins and I haven't experienced it... if you remove this plugin it works well? maybe you installed any new plugin that takes all your memory?

korgoth commented 3 years ago

Strange thing is it was working just fine until i rebooted the RPi.

I still have about 500MB of free memory.

Whats even more odd is that i currently have the plugin installed - just no devices setup - and the Homebridge process is starting and its working. If i add a device - then it hangs. If i remove the device - it starts up again. I have tried with various devices (phones, routers, computers) - every time the same result. :-/

nitaybz commented 3 years ago

node version?

nitaybz commented 3 years ago

homebridge version?

korgoth commented 3 years ago

HB: 1.2.5 Node: 14.15.3

Plugin versions tried: 1.2.3, 1.2.1, 1.2.0

nitaybz commented 3 years ago

can you try and change the homebridge version to 1.1.7?

korgoth commented 3 years ago

I just did - same error

korgoth commented 3 years ago

After todays HB update to 1.3 i set the Network presence plugin to run as a separate process (a child bridge). And the result is the same:

[20/02/2021, 11:52:13] [homebridge-network-presence] Child bridge process ended
[20/02/2021, 11:52:13] [homebridge-network-presence] Process Ended. Code: null, Signal: SIGABRT
[20/02/2021, 11:52:20] [homebridge-network-presence] Restarting Process...
Initializing HAP-NodeJS v0.9.1...
[20/02/2021, 11:52:22] [homebridge-network-presence] Launched external bridge with PID 25884
[20/02/2021, 11:52:23] Registering platform 'homebridge-network-presence.NetworkPresence'
[20/02/2021, 11:52:23] [homebridge-network-presence] Loaded homebridge-network-presence v1.2.3 successfully
Preparing Advertiser for 'homebridge-network-presence 019B' using ciao backend!
[20/02/2021, 11:52:23] [homebridge-network-presence] Initiating Network Scanner...

<--- Last few GCs --->

[25884:0x52bba00]    27183 ms: Scavenge 224.7 (227.8) -> 223.6 (228.3) MB, 27.0 / 0.0 ms  (average mu = 0.351, current mu = 0.224) allocation failure 
[25884:0x52bba00]    27226 ms: Scavenge 225.2 (228.3) -> 224.2 (228.8) MB, 31.9 / 0.0 ms  (average mu = 0.351, current mu = 0.224) allocation failure 
[25884:0x52bba00]    27276 ms: Scavenge 225.6 (228.8) -> 224.7 (229.3) MB, 39.4 / 0.0 ms  (average mu = 0.351, current mu = 0.224) allocation failure 

<--- JS stacktrace --->

FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory
[20/02/2021, 11:52:51] [homebridge-network-presence] Child bridge process ended
korgoth commented 3 years ago

After more testing it seems that network presence is somehow conflicting with MagicHome Dynamic platform plugin. (guess they since they are both scanning the network for devices something times out. I removed the MagicHome Dynamic platform plugin and replaced it with the more simple Homebridge Magichome Platform (https://github.com/sahilchaddha/homebridge-magichome-platform) - where all magic home devices are required to have static IP addresses described in the config. Now everything seems to work correctly.