Getting 502 errors randomly from HAproxy with SH code

I am randomly getting HAProxy 502 errors when I send request to my backend via haproxy.I have put retry on 502.But still I get 502 errors.
I have installed HAProxy on a Ubuntu 18.04 system with 4 cores.
The following is the termination code I get from haproxy logs
502 209 - - SH–
0/0/0/-1/0 which correspond to %TR/%Tw/%Tc/%Tr/%Ta

The following is the configuration.

maxconn 256

mode http
timeout connect 10s
timeout client 30s
timeout server 30s
timeout check 10s
log global
option httplog

frontend mywebapp
bind *:7801
mode http
option httplog
default_backend webservers

backend webservers
mode http
balance roundrobin
retry-on 502
retries 3
server server1 check
server server2 check
server server3 check