redis_version:7.2.4
HAProxy version 2.4.24
redis - docker containers
haproxy - package installation
I'm trying to use two redis servers with haproxy. I don't get this error when I try to connect the redis servers separately, but when I connect them with haproxy, I get this error.
[2024-02-29T02:35:24.933] [ERROR] [localhost] [docId] [userId] nodeJS - redisClient error Error: Socket closed unexpectedly
at Socket.<anonymous> (/snapshot/server/DocService/node_modules/@redis/client/dist/lib/client/socket.js:194:118)
at Object.onceWrapper (node:events:642:26)
at Socket.emit (node:events:527:28)
at TCP.<anonymous> (node:net:709:12)
[2024-02-29T02:35:27.529] [ERROR] [localhost] [docId] [userId] nodeJS - [AMQP] conn error Error: Unexpected close
at succeed (/snapshot/server/Common/node_modules/amqplib/lib/connection.js:272:13)
at onOpenOk (/snapshot/server/Common/node_modules/amqplib/lib/connection.js:254:5)
at /snapshot/server/Common/node_modules/amqplib/lib/connection.js:166:32
at /snapshot/server/Common/node_modules/amqplib/lib/connection.js:160:12
at Socket.recv (/snapshot/server/Common/node_modules/amqplib/lib/connection.js:499:12)
at Object.onceWrapper (node:events:641:28)
at Socket.emit (node:events:527:28)
at emitReadable_ (node:internal/streams/readable:578:12)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
I don't know if this is a configuration issue with haproxy or if I need to do more work on redis.
[haproxy.cfg]
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon
defaults
log global
mode http
#option httplog
option dontlognull
timeout connect 5s
timeout client 10s
timeout server 10s
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
frontend redis_frontend
bind *:6379
mode tcp
default_backend redis_servers
backend redis_servers
mode tcp
balance roundrobin
server redis1 192.168.0.207:6379 check
server redis2 192.168.0.210:6379 check
How can I resolve this issue?
I read that you should try adjusting the timeout setting, so I tried changing the timeout to 60s and then 10s. Not surprisingly, this only changed the frequency of the error logs, but it didn't solve the problem.
Based on
timeout client, HAProxy disconnects inactive connections.Then you need a connection pool to periodically check idle connections, and the period should be less thantimeout client.