hassio-addons / addon-node-red

Node-RED - Home Assistant Community Add-ons
https://addons.community
MIT License
513 stars 117 forks source link

Slow startup when using npm packages #1752

Closed FeikoJoosten closed 7 months ago

FeikoJoosten commented 7 months ago

Problem/Motivation

As the title describes, whenever I use npm packages the addon takes way over 30 minutes to startup. If I remove the npm packages the startup is near instance. This problem started occurring quite recently, I believe whenever I upgraded the supervisor to 2023.11.3. But it could also be that I updated the core to 2023.11.3. I only started noticing this after I updated either one of those and my automations no longer functioned. I unfortunately don't recall which one exactly I upgraded.

My internet is rather speedy 1gbps up and down. And my homeassistant instance doesn't have any internet issues as far as I'm aware of.

I've already fully reinstalled node red (also removed the config folder generated by NR) to see if that was the cause, but even with a fresh install the issue occurs whenever I add a npm package.

My configuration ```yaml theme: midnight-red http_node: username: "" password: "" http_static: username: "" password: "" ssl: false certfile: HIDDEN keyfile: HIDDEN system_packages: [] npm_packages: - node-red-contrib-stoptimer - node-red-contrib-looptimer init_commands: [] credential_secret: HIDDEN require_ssl: true ```
Startup logs ``` s6-rc: info: service s6rc-oneshot-runner: starting s6-rc: info: service s6rc-oneshot-runner successfully started s6-rc: info: service base-addon-banner: starting ----------------------------------------------------------- Add-on: Node-RED Flow-based programming for the Internet of Things ----------------------------------------------------------- Add-on version: 16.0.2 You are running the latest version of this add-on. System: Home Assistant OS 11.1 (amd64 / qemux86-64) Home Assistant Core: 2023.11.3 Home Assistant Supervisor: 2023.11.3 ----------------------------------------------------------- Please, share the above information when looking for help or support in, e.g., GitHub, forums or the Discord chat. ----------------------------------------------------------- s6-rc: info: service base-addon-banner successfully started s6-rc: info: service fix-attrs: starting s6-rc: info: service base-addon-log-level: starting s6-rc: info: service fix-attrs successfully started s6-rc: info: service base-addon-log-level successfully started s6-rc: info: service legacy-cont-init: starting s6-rc: info: service legacy-cont-init successfully started s6-rc: info: service init-nginx: starting s6-rc: info: service init-customizations: starting [15:00:28] INFO: Starting installation of custom NPM/Node-RED packages... s6-rc: info: service init-nginx successfully started npm WARN config optional Use `--omit=optional` to exclude optional dependencies, or npm WARN config `--include=optional` to include them. npm WARN config npm WARN config Default value does install optional deps unless otherwise omitted. npm WARN config only Use `--omit=dev` to omit dev dependencies from the install. added 4 packages, and audited 689 packages in 33m 103 packages are looking for funding run `npm fund` for details 18 vulnerabilities (16 moderate, 2 critical) To address all issues possible (including breaking changes), run: npm audit fix --force Some issues need review, and may require choosing a different dependency. Run `npm audit` for details. s6-rc: info: service init-customizations successfully started s6-rc: info: service init-nodered: starting up to date, audited 2 packages in 3s found 0 vulnerabilities s6-rc: info: service init-nodered successfully started s6-rc: info: service nodered: starting s6-rc: info: service nodered successfully started s6-rc: info: service nginx: starting s6-rc: info: service nginx successfully started s6-rc: info: service legacy-services: starting s6-rc: info: service legacy-services successfully started [15:33:49] INFO: Starting Node-RED... > start > node $NODE_OPTIONS node_modules/node-red/red.js --settings /etc/node-red/config.js 27 Nov 15:33:51 - [info] Welcome to Node-RED =================== 27 Nov 15:33:51 - [info] Node-RED version: v3.1.0 27 Nov 15:33:51 - [info] Node.js version: v18.18.2 27 Nov 15:33:51 - [info] Linux 6.1.59 x64 LE 27 Nov 15:33:51 - [info] Loading palette nodes 27 Nov 15:33:52 - [info] Dashboard version 3.6.1 started at /endpoint/ui 27 Nov 15:33:53 - [info] Settings file : /etc/node-red/config.js 27 Nov 15:33:53 - [info] Context store : 'default' [module=memory] 27 Nov 15:33:53 - [info] User directory : /config/ 27 Nov 15:33:53 - [warn] Projects disabled : editorTheme.projects.enabled=false 27 Nov 15:33:53 - [info] Flows file : /config/flows.json 27 Nov 15:33:53 - [info] Server now running at http://127.0.0.1:46836/ 27 Nov 15:33:53 - [info] Starting flows [15:33:53] INFO: Starting NGinx... 27 Nov 15:33:54 - [info] Started flows ```

Expected behavior

The npm packages option shouldn't take ages to load/download/install.

Actual behavior

Starting the addon with the npm packages option configured causes the addon to have a startup time of 30+ minutes

Steps to reproduce

Add one of these npm packages node-red-contrib-stoptimer node-red-contrib-looptimer. I haven't confirmed if different npm packages cause similar issues.

Proposed changes

N/A

sinclairpaul commented 7 months ago

I doubt there is much we can do here, it will be something local, neither Core or the Supervisor should have any impact to the download speed from the container. It could possibly be you are hitting some kind of rate limit from Github/NPM.

As a comparison added 4 packages, and audited 689 packages in 7s

FeikoJoosten commented 7 months ago

Would you happen to know where I could check this?

sinclairpaul commented 7 months ago

Unfortunately not, it doesn't look like the NPM Registry limiting is documented by Github yet, if it exists.

My suggestion would be to try and reproduced it outside of the HA environment, it's just an npm install that is happening so you could run that anywhere else.

FeikoJoosten commented 7 months ago

The interesting part is that before I updated supervisor/core I didn't have this issue at all. And similarly the packages downloaded in a couple of seconds rather than minutes. My OS still has plenty of disk space left, and looking at glances while the addon is booting doesn't indicate the CPU reaching 100% usage, so I wouldn't imagine that being the cause either.

I'll try your suggestion to do an npm install seeing if that's the case, but I doubt that's it. Nonetheless, it's worth a shot.

FeikoJoosten commented 7 months ago

Running npm i node-red-contrib-stoptimer on the machine hosting the VM containing my home assistant setup it installs the package in 5 seconds. So I'd argue the issue is most likely contained in the VM. Is there something I can share to help figure out what's causing the issue? Or would you rather have me close this as it may or may not be related to the node red addon?

FeikoJoosten commented 7 months ago

Actually, I'm going to be closing this issue as simply restarting my homeassistant instance is taking more than 10 minutes. Normally this is less than a minute or so. Possibly something in the supervisor/core update causing an issue.

FeikoJoosten commented 7 months ago

In case someone is curious. Turned out the issue was caused by an incorrect ipv6 assignment of my homeassistant instance. Sounds like I'm not the only one as I found out the solution from this post. https://community.home-assistant.io/t/timeout-on-various-http-requests-from-ha-to-external-services/515874/2. After disabling the ipv6 network interface and a reboot of homeassistant everything functions as desired again.