大网数据广告活动
服务器运维问答

HAProxy still return 502 after 120seconds

· 52CE 我爱测

I have HAProxy configured that will forward my http requests to various services on internal ports. One of this service may take some minutes to elaborate an answer, but after 120s HAProxy will still return a 502 Bad Gateway erro…

问题原文

原帖链接 · Leonardo Rossi · CC BY-SA 4.0

I have HAProxy configured that will forward my http requests to various services on internal ports.

One of this service may take some minutes to elaborate an answer, but after 120s HAProxy will still return a 502 Bad Gateway error.

I have tried to set higher timeouts without any success. Here is the haproxy.cfg file

global
    daemon
    maxconn 4096
    log 127.0.0.1 local0
defaults
    mode http
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms
    option forwardfor
    option http-server-close
    log global

frontend http-in
    bind *:80
    option tcplog
    default_backend my_default_backend
    timeout client 10m
    timeout server 10m

    acl is_test_request hdr(host) -i testrequest.mydomain.ext
    use_backend test_timeout if is_test_request

backend test_timeout
    timeout connect 10s
    timeout server 10m
    server s1 127.0.0.1:8099

listen admin
    bind *:8080
    stats enable

Yes, there are repeated timeout directives, this is the file after few tests I made.

There are also some other acl and use_backend but I have trimmed them out.

How can I set an higher timeout for that service?

Update:

This is a sample log line

May 22 07:25:52 localhost haproxy[2552]: CLIENT_IP_REDACTED:PORT [22/May/2018:07:23:52.402] http-in test_timeout/s1 0/0/120004 204 SH 0/0/0/0/0 0/0

the service listening on port 8099 was waiting 180seconds to send a response, but after 120 haproxy sent back a

502 Bad Gateway

The server returned an invalid or incomplete response.

已采纳解答

原帖链接 · Michael - sqlbot · CC BY-SA 4.0

The SH in your log entry tells the story. This field is called Session State at Disconnection, and is tremendously valuable. What you logged suggests that you need to look more closely at the web server's configuration and behavior. The web server itself appears to be closing the connection while HAProxy is waiting for the response.

Here's how I arrived at this conclusion:

S: the TCP session was unexpectedly aborted by the server, or the server explicitly refused it.

We know that the server didn't refuse the connection, so we assume the server closed it, and look to the second value.

H: the proxy was waiting for complete, valid response HEADERS from the server (HTTP only).

So, before the proxy had received the \r\n\r\n following a set of valid HTTP response headers, the web server unexpectedly closed the connection.

http://cbonte.github.io/haproxy-dconv/1.6/configuration.html#8.5

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-05-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。