I’m having a repeating issue that meets me every few month.
The problem is that suddenly i see on PostgreSQL lots of “idle in transaction” for about 1 second and also, on PostgreSQL logs i get lots of “could not receive data from client: Connection reset by peer” errors.

To fix the issue i need to restart HAProxy service.
I dont understand what causing HAProxy to reset the connections.
I know that on regular times, its expected to see such error on PostgreSQL while HAProxy is the LB.

Any ideas ?

My architecture:
2 HAProxy (2.1.7) nodes with Keepalived
PostgreSQL managed by Patroni

Attaching my HAProxy configuration:

maxconn 3000
log local0 info

log global
mode tcp
retries 1
timeout client 1m
timeout connect 2s
timeout server 1m
timeout check 2s

listen stats
mode http
bind *:7000
stats enable
stats uri /

frontend frontend_postgres
bind *:5000
default_backend backend_postgres

backend backend_postgres
option httpchk OPTIONS /master
http-check expect status 200

balance leastconn
server PostgreSQL01 PostgreSQL01:5432 check port 8008
server PostgreSQL02 PostgreSQL02:5432 check port 8008