haproxy will get 404 error for about 2-3 seconds if one of backend server down

允我心安 提交于 2021-02-11 13:08:40

问题


this is the haproxy config.

defaults
  option forwardfor
  log global
  option httplog
  log 127.0.0.1 local3
  option  dontlognull
  retries 3
  option redispatch
  timeout connect 5000ms
  timeout client  5000ms
  timeout server 5000ms

listen stats
    bind    *:9000
    mode    http
..............................................
backend testhosts
    mode http
    balance roundrobin
    option httpchk HEAD /sabrix/scripts/menu-common.js
    server host1 11.11.11.11:9080  check inter 2000 rise 1 fall 2
    server host2 11.11.11.12:9080  check inter 2000 rise 1 fall 2

if service of 11.11.11.11 is down, haproxy will get 503 and 404 error about 2-3 seconds( it depends inter value, if inter value is very small, the number of 404 error will be decreased).

2020-08-25T11:58:14 11.11.11.11:9080 200 POST /tsturl1 HTTP/1.1 2274
2020-08-25T11:58:14 11.11.11.22:9080 200 POST /tsturl1 HTTP/1.1 448
2020-08-25T11:58:14 11.11.11.11:9080 503 POST /tsturl1 HTTP/1.1 0
2020-08-25T11:58:14 11.11.11.11:9080 404 POST /tsturl1 HTTP/1.1 0
2020-08-25T11:58:14 11.11.11.11:9080 200 POST /tsturl1 HTTP/1.1 1503
2020-08-25T11:58:16 11.11.11.22:9080 200 POST /tsturl1 HTTP/1.1 617
2020-08-25T11:58:16 11.11.11.11:9080 404 POST /tsturl1 HTTP/1.1 0
2020-08-25T11:58:16 11.11.11.22:9080 200 POST /tsturl1 HTTP/1.1 618
2020-08-25T11:58:16 11.11.11.11:9080 404 POST /tsturl1 HTTP/1.1 0
2020-08-25T11:58:16 host1 is DOWN, reason: Layer7 wrong status, code: 404, info: "Not Found", check duration: 0ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue. 2020-08-25T11:58:16 11.11.11.22:9080 200 POST /tsturl1 HTTP/1.1 645
2020-08-25T11:58:16 11.11.11.22:9080 200 POST /tsturl1 HTTP/1.1 618\

My question is : why the parameter retry didn't work ? is it possible for the user always get 200 code rather than 400 error even when one of the backend server down ? I'm using Haproxy 1.5.18.

THanks a lot


回答1:


In the version you are using retries is for Layer 4 (i.e. connection timeout). HAProxy 2.0 introduced Layer 7 retries. These 2 blog posts may be helpful:

HAProxy 2.0

Layer 7 Retries and Chaos Engineering



来源:https://stackoverflow.com/questions/63582064/haproxy-will-get-404-error-for-about-2-3-seconds-if-one-of-backend-server-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!