Haproxy websocket disconnected after few seconds

Hello,

I am using HAproxy 1.5.8 version for http and now try to add websocket support.

I am testing using http://www.websocket.org/echo.html site for websocket connection.

My websocket connection connects to the server but after around few seconds it shows disconnected.

My setup is like this:

AWS ALB -----> HAproxy ------> ec2 with web app docker container

I have enabled the session stickiness attribute on AWS ALB.

haproxy conf:

defaults
mode http
timeout connect 5000ms
timeout client 5000ms
timeout server 50000ms

timeout tunnel  3600s
timeout client-fin 30s
timeout http-keep-alive  1s

option          httplog
option          redispatch
retries         3
log             global

frontend public
bind 0.0.0.0:80
option dontlognull
option forwardfor
maxconn 2500
monitor-uri /haproxy_health
option httplog
# remove proxy header
http-request del-header Proxy

## **WS routing based on Host header
acl host_ws hdr_beg(Host) -i ws.
use_backend meteoguard-task-list-service-eis if host_ws

## **WS routing based on websocket protocol header
acl hdr_connection_upgrade hdr(Connection)  -i upgrade
acl hdr_upgrade_websocket  hdr(Upgrade)     -i websocket
use_backend meteoguard-task-list-service-eis if hdr_connection_upgrade hdr_upgrade_websocket

################################################################################################
backend meteoguard-task-list-service-eis
balance roundrobin
option tcplog
timeout connect 30s
timeout client 30s
timeout server 30s
option forwardfor
timeout tunnel 60m
## websocket protocol validation
acl hdr_connection_upgrade hdr(Connection) -i upgrade
acl hdr_upgrade_websocket hdr(Upgrade) -i websocket
acl hdr_websocket_key hdr_cnt(Sec-WebSocket-Key) eq 1
acl hdr_websocket_version hdr_cnt(Sec-WebSocket-Version) eq 1
http-request deny if ! hdr_connection_upgrade ! hdr_upgrade_websocket ! hdr_websocket_key ! hdr_websocket_version

option httpchk  GET /health
http-check expect status 200

server ws1 10.3.1.2:31402 check

Please share the logs.

Thanks for the reply. Now i found out that when i directly use the haproxy server ip in url, this session remains connected but when i use AWS ALB DNS in url the session get disconnected.

I have also enable the session stickiness on ALB but still no effect. Any idea what needs to be changed?

AWS ELB does not support websockets in HTTP mode.

See:
https://www.built.io/blog/websockets-on-aws-s-elb

I am using new ALB(application load balancer).

In ALB i have added haproxy instances as a target group.

At ALB I am getting , failed: Error during WebSocket handshake: Unexpected response code: 302 error. any ideas?

No ideas. I suggest you contact Amazon.