Several node-red containers are reported as unhealthy by docker

Lately I noticed that several of my node-red containers are reported as unhealthy by docker.

This is the inspect output for such a container

{
    "Id": "b282259f2feb6bbbe6e46ca6a56efa25f24c25d152cd2601d236740d7b26fbf0",
    "Created": "2024-08-12T14:30:07.063943378Z",
    "Path": "./entrypoint.sh",
    "Args": [],
    "State": {
        "Status": "running",
        "Running": true,
        "Paused": false,
        "Restarting": false,
        "OOMKilled": false,
        "Dead": false,
        "Pid": 3078,
        "ExitCode": 0,
        "Error": "",
        "StartedAt": "2024-08-13T11:53:54.875344403Z",
        "FinishedAt": "2024-08-13T11:53:00.02949769Z",
        "Health": {
            "Status": "unhealthy",
            "FailingStreak": 478,
            "Log": [
                {
                    "Start": "2024-08-13T17:53:04.336514692+02:00",
                    "End": "2024-08-13T17:53:04.606846869+02:00",
                    "ExitCode": 1,
                    "Output": ""
                },
                {
                    "Start": "2024-08-13T17:53:34.607796346+02:00",
                    "End": "2024-08-13T17:53:34.917576805+02:00",
                    "ExitCode": 1,
                    "Output": ""
                },
...
        "Healthcheck": {
            "Test": [
                "CMD-SHELL",
                "node /healthcheck.js"
            ]
        },
...

FYI the contents of the healtcheck.js

b282259f2feb:/$ cat healthcheck.js 
var http = require('http');
var https = require('https');
var settings = require('/data/settings.js');
var request;

process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;

var options = {
    host : "localhost",
    port : settings.uiPort || 1880,
    timeout : 4000
};

if (settings.hasOwnProperty("https")) {
    request = https.request(options, (res) => {
        //console.log(`STATUS: ${res.statusCode}`);
        if ((res.statusCode >= 200) && (res.statusCode < 500)) { process.exit(0); }
        else { process.exit(1); }
    });
}
else {
    request = http.request(options, (res) => {
        //console.log(`STATUS: ${res.statusCode}`);
        if ((res.statusCode >= 200) && (res.statusCode < 500)) { process.exit(0); }
        else { process.exit(1); }
    });
}

request.on('error', function(err) {
    //console.log('ERROR',err);
    process.exit(1);
});

request.end(); b282259f2feb:/$ 

I have uncommented the log statement at the end in the healtcheck.js and then manually executed the healthcheck in the container. This is what I get:

b282259f2feb:/tmp$ node check.js 
ERROR Error: connect ECONNREFUSED ::1:1880
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 1880
}
b282259f2feb:/tmp$ 

If I replace localhost by 127.0.0.1 the healthcheck is working.
So the problem is that it is using ipv6 address ::1 for localhost while it is only listening for ipv4 addresses:

b282259f2feb:/tmp$ netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       
tcp        0      0 localhost:40789         0.0.0.0:*               LISTEN      
tcp        0      0 0.0.0.0:1880            0.0.0.0:*               LISTEN  
...

I don't have this for all my node-red containers when comparing the only difference is that localhost is not mapped to ipv6 address "::1" when it is working.

So this is from a container having the problem:

82259f2feb:~$ node --version
v18.18.2
b282259f2feb:~$ uname -a
Linux b282259f2feb 6.5.0-44-generic #44-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun  7 15:10:09 UTC 2024 x86_64 Linux
b282259f2feb:~$ 

This is from a container not having the problem:

bash-5.1$ node --version
v16.16.0
bash-5.1$ uname -a
Linux bd6ae5207f57 6.5.0-44-generic #44-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun  7 15:10:09 UTC 2024 x86_64 Linux
bash-5.1$ 

So the problem seems to be caused by more recent node version.

Problem got introduced by node version 17

1 Like

The problem got fixed by upgrading node-red to docker image nodered/node-red:4.0.2-22
as this is using node version v22.6.0 which doesn't have this problem.

Welcome to Node-RED
===================

13 Aug 21:37:01 - [info] Node-RED version: v4.0.2
13 Aug 21:37:01 - [info] Node.js  version: v22.6.0
13 Aug 21:37:01 - [info] Linux 6.5.0-44-generic x64 LE

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.