首页 > 解决方案 > haproxy + spring boot writeAddress(..)失败:对等方重置连接

问题描述

我正在使用后端 Spring Boot Rest 控制器运行 HAproxy。我的 spring 日志显示如下所示的持续错误:

[reactor-http-epoll-26] ERROR o.s.w.s.a.HttpWebHandlerAdapter - [9df8bfcf] Error [io.netty.channel.unix.Errors$NativeIoException: writeAddress(..) failed: Connection reset by peer] for HTTP GET "/api/v1/status", but ServerHttpResponse already committed (200 OK)

HAproxy 对 url 执行 HTTP 检查/api/v1/status。我收到这些错误的原因是什么?

HAProxy 配置

global
    log         127.0.0.1 local2
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    # daemon
    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats
    ssl-default-bind-ciphers  EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH+aRSA+RC4:EECDH:EDH+aRSA:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EX$
    ssl-default-bind-options no-sslv3 no-tlsv10
    tune.ssl.default-dh-param 4096

defaults
    mode                    http
    log                     global
    option                  httplog
    option                  http-server-close
    option forwardfor       except 127.0.0.0
    option                  redispatch
    retries                 3
    timeout http-request    30s
    timeout queue           1m
    timeout connect         30s
    timeout client          30s
    timeout server          30s

frontend https-in
    bind *:443 ssl crt /etc/cert.pem
    default_backend api

backend api
    mode http
    option httpchk GET /api/v1/status HTTP/1.0
    http-check expect status 200
    balance roundrobin
    server api1 127.0.0.1:8001 check fall 3 rise 2
    server api2 127.0.0.1:8002 check fall 3 rise 2

标签: springspring-boothaproxy

解决方案


HAproxy 正在执行 GET 请求,读取 http 响应代码并关闭连接。Boot 正在尝试发送剩余部分(http 标头和一些 json 有效负载),但连接已关闭。

只需将 GET 替换为 OPTIONS 即可:

option httpchk GET /api/v1/status HTTP/1.0


推荐阅读