WebThingsIO / gateway

WebThings Gateway
http://webthings.io/gateway
Mozilla Public License 2.0
2.61k stars 336 forks source link

Error when unloading add-on #2497

Open dhylands opened 6 years ago

dhylands commented 6 years ago

After disabling the thing-url-adapter, it continues to run:

2018-05-03 17:20:19.658 thing-url: getValue for property level for: My Humidity Sensor returning -13.439418712793357
2018-05-03 17:20:22.661 thing-url: getValue for property level for: My Humidity Sensor returning 15.255113852579065
2018-05-03 17:20:22.712 Failed to toggle add-on thing-url-adapter
2018-05-03 17:20:22.713 TypeError: Cannot read property 'unload' of undefined
    at AddonManager.unloadAddon (/home/pi/mozilla-iot/gateway/build/webpack:/src/addon-manager.js:799:1)
    at ./src/controllers/addons_controller.js.AddonsController.put (/home/pi/mozilla-iot/gateway/build/webpack:/src/controllers/addons_controller.js:74:1)
    at <anonymous>
2018-05-03 17:20:25.667 thing-url: getValue for property level for: My Humidity Sensor returning -18.338738292831156
2018-05-03 17:20:28.671 thing-url: getValue for property level for: My Humidity Sensor returning 14.723809043151501
2018-05-03 17:20:31.674 thing-url: getValue for property level for: My Humidity Sensor returning -1.065696371447572
2018-05-03 17:20:34.690 thing-url: getValue for property level for: My Humidity Sensor returning 5.591584829714968
2018-05-03 17:20:37.682 thing-url: getValue for property level for: My Humidity Sensor returning -23.333073303242777
mrstegeman commented 6 years ago

Well, this is strange. This is the code that's failing:

...
} else if (plugin) {
  plugin.unload();
}

... So how is plugin undefined when calling unload() on it?

madb1lly commented 4 years ago

Hi @mrstegeman and @dhylands,

I just got this error with https://github.com/flatsiedatsie/webthings-network-presence-detection. What's the fix/workaround please?

Thanks 🙂

mrstegeman commented 4 years ago

@madb1lly Do you have a log showing the error? It may be different from this one.

madb1lly commented 4 years ago

Hi @mrstegeman, Disable add-on:

2020-05-28 07:46:01.361 ERROR : Failed to toggle add-on network-presence-detection-adapter 2020-05-28 07:46:01.459 ERROR : TypeError: Cannot read property 'send' of undefined at Plugin.sendMsg (/home/pi/mozilla-iot/gateway/build/webpack:/src/plugin/plugin.js:580:1) at Plugin.unload (/home/pi/mozilla-iot/gateway/build/webpack:/src/plugin/plugin.js:737:1) at AddonManager.unloadAddon (/home/pi/mozilla-iot/gateway/build/webpack:/src/addon-manager.js:963:1) at AddonManager.disableAddon (/home/pi/mozilla-iot/gateway/build/webpack:/src/addon-manager.js:599:1)

Enable add-on:

2020-05-28 07:48:44.393 INFO : Loading add-on: network-presence-detection-adapter 2020-05-28 07:48:44.601 INFO : Unhandled Rejection 2020-05-28 07:48:44.638 ERROR : { Error: spawn ENOMEM at ChildProcess.spawn (internal/child_process.js:366:11) at spawn (child_process.js:551:9) at startPromise.Settings.get.then (/home/pi/mozilla-iot/gateway/build/webpack:/src/plugin/plugin.js:644:1) errno: 'ENOMEM', code: 'ENOMEM', syscall: 'spawn' }

Removing add-on:

2020-05-28 07:49:18.392 ERROR : Failed to unload network-presence-detection-adapter properly: TypeError: Cannot read property 'send' of undefined

Re-installing add-on:

2020-05-28 07:50:41.349 INFO : Fetching add-on https://s3-us-west-2.amazonaws.com/mozilla-gateway-addons/network-presence-detection-adapter-0.1.2.tgz as /tmp/x74vae/network-presence-detection-adapter.tar.gz 2020-05-28 07:50:45.431 INFO : Expanding add-on /tmp/x74vae/network-presence-detection-adapter.tar.gz 2020-05-28 07:50:48.754 ERROR : Failed to unload network-presence-detection-adapter properly: TypeError: Cannot read property 'send' of undefined 2020-05-28 07:50:55.087 INFO : Loading add-on: network-presence-detection-adapter 2020-05-28 07:50:55.309 INFO : Unhandled Rejection 2020-05-28 07:50:55.341 ERROR : { Error: spawn ENOMEM at ChildProcess.spawn (internal/child_process.js:366:11) at spawn (child_process.js:551:9) at startPromise.Settings.get.then (/home/pi/mozilla-iot/gateway/build/webpack:/src/plugin/plugin.js:644:1) errno: 'ENOMEM', code: 'ENOMEM', syscall: 'spawn' }

I've tried rebooting and it doesn't have an effect.

Is it the same issue? If yes and you think it's a gateway issue then I'll raise a new issue here.

Cheers 🙂

mrstegeman commented 4 years ago

I'm unable to reproduce, but this seems problematic to me:

2020-05-28 07:48:44.638 ERROR  : { Error: spawn ENOMEM
    at ChildProcess.spawn (internal/child_process.js:366:11)
    at spawn (child_process.js:551:9)
    at startPromise.Settings.get.then (/home/pi/mozilla-iot/gateway/build/webpack:/src/plugin/plugin.js:644:1) errno: 'ENOMEM', code: 'ENOMEM', syscall: 'spawn' }

It seems like there may be a memory leak somewhere (in the adapter?). Is there anything else running on your Pi? Perhaps we're hitting the upper memory bound of your Pi?

madb1lly commented 4 years ago

No nothing else running, it's for the gateway only. You may be right about memory though, it is only a 512MB Model B and when trying to do these things it had ~50MB free, which is a bit tight. A month or so ago it used to be ~125MB free though and I've not figured out what changed.

mrstegeman commented 4 years ago

You might want to watch top and try to figure out what’s using so much memory and/or leaking.

You could also try to add a swap file to your RPi, although its performance is going to be pretty terrible on the SD card.

flatsiedatsie commented 3 years ago

Perhaps this error I'm seeing is related:

2021-02-04 07:41:20.949 ERROR  : Failed to restart add-on voco
2021-02-04 07:41:20.988 ERROR  : TypeError: Cannot read property 'send' of undefined
    at Plugin.sendMsg (/home/pi/mozilla-iot/gateway/build/webpack:/src/plugin/plugin.js:580:1)
    at Plugin.unload (/home/pi/mozilla-iot/gateway/build/webpack:/src/plugin/plugin.js:737:1)
    at AddonManager.unloadAddon (/home/pi/mozilla-iot/gateway/build/webpack:/src/addon-manager.js:979:1)
    at ./src/controllers/addons_controller.js.AddonsController.put (/home/pi/mozilla-iot/gateway/build/webpack:/src/controllers/addons_controller.js:111:1)
2021-02-04 07:41:51.130 ERROR  : Failed to restart add-on voco
2021-02-04 07:41:51.150 ERROR  : TypeError: Cannot read property 'send' of undefined
    at Plugin.sendMsg (/home/pi/mozilla-iot/gateway/build/webpack:/src/plugin/plugin.js:580:1)
    at Plugin.unload (/home/pi/mozilla-iot/gateway/build/webpack:/src/plugin/plugin.js:737:1)
    at AddonManager.unloadAddon (/home/pi/mozilla-iot/gateway/build/webpack:/src/addon-manager.js:979:1)
    at ./src/controllers/addons_controller.js.AddonsController.put (/home/pi/mozilla-iot/gateway/build/webpack:/src/controllers/addons_controller.js:111:1)

This is on a Pi zero. No messages about being out of memory. And the latest version of Voco should theoretically use less memory, since the hotword detection no longer runs on it, but is taken care of by the central voco server.

flatsiedatsie commented 3 years ago

Hmm, I do see this ENOMEM a bit further in the log...

2021-02-04 08:23:56.488 ERROR  : Failed to toggle add-on voco
2021-02-04 08:23:56.510 ERROR  : TypeError: Cannot read property 'send' of undefined
    at Plugin.sendMsg (/home/pi/mozilla-iot/gateway/build/webpack:/src/plugin/plugin.js:580:1)
    at Plugin.unload (/home/pi/mozilla-iot/gateway/build/webpack:/src/plugin/plugin.js:737:1)
    at AddonManager.unloadAddon (/home/pi/mozilla-iot/gateway/build/webpack:/src/addon-manager.js:979:1)
    at AddonManager.disableAddon (/home/pi/mozilla-iot/gateway/build/webpack:/src/addon-manager.js:615:1)
2021-02-04 08:24:48.343 INFO   : Loading add-on: voco
2021-02-04 08:24:48.465 INFO   : Unhandled Rejection
2021-02-04 08:24:48.489 ERROR  : { Error: spawn ENOMEM
    at ChildProcess.spawn (internal/child_process.js:366:11)
    at spawn (child_process.js:551:9)
    at startPromise.Settings.get.then (/home/pi/mozilla-iot/gateway/build/webpack:/src/plugin/plugin.js:644:1) errno: 'ENOMEM', code: 'ENOMEM', syscall: 'spawn' }
flatsiedatsie commented 3 years ago

I think I discovered what was causing my issue:

benfrancis commented 3 years ago

@flatsiedatsie wrote:

pagekyte is using a lot of what little memory is left on a Raspberry Pi zero.

Just a thought, but if the gateway is getting tight on memory on a 512MB RAM device, one place we might be able to reduce memory usage slightly (other than more drastic steps like replacing the base OS!) is by replacing pagekite.py with libpagekite, which is written in C and is intended for embedded applications.