Fix AggregateError crashes on Node.js 20+ caused by Happy Eyeballs (autoSelectFamily)#61
Conversation
Disable autoSelectFamily (Happy Eyeballs RFC 6555) to prevent AggregateError crashes in Node-RED nodes using @cypress/request (e.g., node-red-contrib-telegrambot). Node.js 20+ enables autoSelectFamily by default, which tries IPv4 and IPv6 connections simultaneously. When both fail, it throws AggregateError which older HTTP libraries don't handle properly. Fixes issues with: - node-telegram-bot-api (uses @cypress/request) - Other Node-RED nodes using deprecated request libraries References: - yagop/node-telegram-bot-api#1193 - nodejs/node#46790
|
Don't love this because it is global, right? This will affect the server and other plugins. If we want to turn this off, we should probably do it in the server. Or you could do it in a function node? What do you think @tkurki |
|
I understand your concerns, so we should address this properly. Node-Red will be a show stopper to lift SignalK to node 24. You have not been a lot involved in the Universal Installer that runs podman containers. My idea would be to put the node-red-plugin into a container and during App Store install to spin it up. Architecture SketchNode-RED just uses the existing Why This Is a Great FitComplete process isolation - Node-RED runs in its own container with its own Node.js process. The Other benefits you get for free:
If this interests you than I am more than happy to share additional details. |
|
The current node-red contrib does not work in a separate node-red process. It uses the plugin apis. Some of the functionality is not available externally. |
I am fully aware of this, it would be a refactoring to a containerized runtime. Would you be open minded for this, if I give it a try? |
yes, but I think we need two versions of the nodes or to make the nodes detect when running embedded and use the plugin api's, and one that uses WebSockets. Nodes like input-handler and send-nmea2000/0183 won't work unless some support is added to the server to do these over WS. |
|
This issue is only problem for node-red-contrib-telegrambot or for node-red in general? I thought I tested with v24. |
I have not tested everything in detail tbo. That was the first thing that I saw was broken.
Thanks for the hint. I will look into it mid Feb I think, after returning from my trip. |
|
No, let’s not start changing global node level defaults for a single add on of a plugin. Why would this even crop up now if it’s been in Node since 20? Remote SK nodes is 100% separate issue, let’s try to keep discussion organised. End users do read this stuff and mixing separate things into a mishmash results in misguided advice and confused people. Ask me how I know. |
|
Well, maybe 96% separate. |
Summary
AggregateErrorin HTTP librariesProblem
Node.js 20+ enables
autoSelectFamilyby default, which implements RFC 6555 "Happy Eyeballs" - attempting IPv4 and IPv6 connections simultaneously. When both connection attempts fail, Node.js throws anAggregateError.Libraries using
@cypress/request(includingnode-telegram-bot-apiused bynode-red-contrib-telegrambot) don't handleAggregateErrorproperly, causing unhandled exceptions and plugin crashes.Example error:
Solution
Disable
autoSelectFamilyat plugin initialization by callingnet.setDefaultAutoSelectFamily(false). This is placed at the very top ofindex.jsbefore any dependencies are loaded, ensuring it applies globally to all network connections.References
Testing
Tested on SignalK server running Node.js v24.13.0 with
node-red-contrib-telegrambot. Before the fix, continuousAggregateErrorcrashes occurred. After the fix, no errors and stable operation.