There's a server on which two dockerized application instances run. One of them has Redis running on default port 6379, the other one, described below, runs Redis on port 7379.
When I try to start a server instance, the following error gets displayed:
sw_redis | 1:C 31 Aug 2023 12:04:33.661 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
sw_redis | 1:C 31 Aug 2023 12:04:33.661 # Redis version=6.2.1, bits=64, commit=00000000, modified=0, pid=1, just started
sw_redis | 1:C 31 Aug 2023 12:04:33.661 # Configuration loaded
sw_redis | 1:M 31 Aug 2023 12:04:33.661 * monotonic clock: POSIX clock_gettime
sw_redis | 1:M 31 Aug 2023 12:04:33.662 * Running mode=standalone, port=7379.
sw_redis | 1:M 31 Aug 2023 12:04:33.662 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
sw_redis | 1:M 31 Aug 2023 12:04:33.662 # Server initialized
sw_redis | 1:M 31 Aug 2023 12:04:33.662 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
sw_redis | 1:M 31 Aug 2023 12:04:33.662 * Ready to accept connections
sw_server | node:internal/process/promises:288
sw_server | triggerUncaughtException(err, true /* fromPromise */);
sw_server | ^
sw_server |
sw_server | Error: connect ECONNREFUSED 127.0.0.1:6379
sw_server | at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16)
sw_server | Emitted 'error' event on Commander instance at:
sw_server | at RedisSocket.<anonymous> (/app/node_modules/@redis/client/dist/lib/client/index.js:395:14)
sw_server | at RedisSocket.emit (node:events:514:28)
sw_server | at RedisSocket._RedisSocket_connect (/app/node_modules/@redis/client/dist/lib/client/socket.js:166:18)
sw_server | at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
sw_server | at async prepareServer (file:///app/setupServer.js:97:5)
sw_server | at async startServer (file:///app/setupServer.js:111:20)
sw_server | at async file:///app/server.js:4:5 {
sw_server | errno: -111,
sw_server | code: 'ECONNREFUSED',
sw_server | syscall: 'connect',
sw_server | address: '127.0.0.1',
sw_server | port: 6379
sw_server | }
sw_server |
sw_server | Node.js v18.17.1
sw_server exited with code 1
The fragment referred by the error dump is here:
const pubClient = createClient({
host: REDIS_HOST,
port: REDIS_PORT,
no_ready_check: true,
auth_pass: REDIS_PASSWORD,
});
const subClient = pubClient.duplicate();
await pubClient.connect();
await subClient.connect();
Also, the Redis client gets created this way, as described in documentation:
const client = createClient({
legacyMode: true,
password: REDIS_PASSWORD,
socket: {
host: REDIS_HOST,
port: REDIS_PORT
}
});
client.on('error', (err) => console.log('Redis Client Error', err));
The client's version: "redis": "^4.6.7"
.
Docker builds the images and runs containers based on this docker-compose.yml
:
version: '3'
services:
server:
container_name: sw_server
networks:
- sw_net
build: .
environment:
REDIS_HOST: sw_redis
REDIS_PORT: 7379
REDIS_PASSWORD: 'Redis-Password-08'
ports:
- '3017:4000'
depends_on:
- sw_redis
links:
- sw_redis
sw_redis:
image: redis
environment:
REDIS_PASSWORD: 'Redis-Password-08'
networks:
- sw_net
command: redis-server --requirepass "Redis-Password-08" --port 7379
ports:
- '7379:7379'
networks:
sw_net:
external: true
Already tried solutions described here, here and here (BTW: you should check the low-pointed answer there, it's awesome ;-)).
None of the solutions posted worked. Hardcoding e.g. port number in JS code didn't work either: somehow the connection routes to port 6379 and gets refused there, because it's a different instance. Mine works on port 7379, but no requests arrive to it.
Any ideas how to debug it further?