V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
httpbin - 协议调试工具
httpstatuses - 协议状态码查询
httpie - cURL-like tool for humans
Fiddler
vevlins
V2EX  ›  HTTP

短时间发送大量请求 http 返回 421

  •  
  •   vevlins · 2019-10-15 17:43:39 +08:00 · 3543 次点击
    这是一个创建于 1626 天前的主题,其中的信息可能已经有所发展或是发生改变。

    421 的原因到底是什么?谷歌的结果看不明白“This can be sent by a server that is not configured to produce responses for the combination of scheme and authority that are included in the request URI.”

    421 怎么解决呢?

    3 条回复    2019-10-16 16:13:50 +08:00
    vevlins
        1
    vevlins  
    OP
       2019-10-15 20:55:01 +08:00
    在 RFC 中找到了一个合理的答案," A server that does not wish clients to reuse connections can indicate
    that it is not authoritative for a request by sending a 421
    (Misdirected Request) status code in response to the request (see
    Section 9.1.2).",golang 中复用了 http 长链接,我这里请求的客户端似乎会检测一个长连接上的请求次数,如果超过一定量就会返回 421.
    lingbopc
        2
    lingbopc  
       2019-10-16 12:50:32 +08:00   ❤️ 1
    server 端是 nginx 么?有一个指令会指定一个长连接最多可以处理端请求数量,你可以参考一下

    keepalive_requests 指令用于设置一个 keep-alive 连接上可以服务的请求的最大数量,当最大请求数量达到时,连接被关闭。默认是 100
    当一个 keep alive 建立之后,nginx 就会为这个连接设置一个计数器,记录这个 keep alive 的长连接上已经接收并处理的客户端请求的数量。如果达到这个参数设置的最大值时,nginx 会强制关闭这个长连接,使得客户端必须重新建立长连接
    当 qps 较大时,建议增加这个值,否则会导致大量的 TIME_WAIT 的 socket 连接
    vevlins
        3
    vevlins  
    OP
       2019-10-16 16:13:50 +08:00
    @lingbopc 是的,找到了。但是我有一个疑问是在一个 keep-alive 上当达到一定数量后就会返回 421,但是几次之后又正常了。我使用的是 golang,这里失败几次后又正常是 nginx 又接受了还是 golang http 底层新开了一个长连接呢?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1191 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:25 · PVG 02:25 · LAX 11:25 · JFK 14:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.