为什么在服务器重置 TCP 后用户代理重新提交请求? [英] Why does the user agent resubmit a request after server does a TCP reset?

查看:24
本文介绍了为什么在服务器重置 TCP 后用户代理重新提交请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近注意到一个问题,即一些用户代理会重复相同的 POST 请求,而用户实际上并未实际触发两次.

We've recently noticed a problem where some user agents would repeat the same POST request without the user actually physically triggering it twice.

经过进一步研究,我们注意到只有在请求通过我们的负载均衡器并且服务器需要很长时间来处理请求时才会发生这种情况.数据包捕获会话最终显示负载均衡器在 5 分钟超时后通过向客户端发送 TCP 重置来断开连接;但是,客户端会在没有用户干预的情况下自动重新提交请求.

After further study, we noticed this only happens when the request goes through our load balancer and when the server took a long time to process the request. A packet capture session eventually revealed that the load balancer drops the connection after a 5 minute timeout by sending a TCP Reset to the client; however, the client automatically resubmitted the request without user intervention.

我们在 Java、Firefox 和 IE 8 的 Apache HTTP 客户端中观察到了这种行为.(我无法安装其他浏览器进行测试.)这让我认为这种行为是 HTTP 标准的一部分,但这对 google 来说不是很容易.

We observed this behavior in Apache HTTP client for Java, Firefox and IE 8. (I cannot install other browsers to test.) This makes me think this behavior is part of the HTTP standard, but this is not very easy to google.

此外,这似乎只有在通过保持活动的 TCP 连接提交第一个请求时才会发生.

Also, it seems this only happen if the first request is submitted via a kept-alive TCP connection.

推荐答案

这是 HTTP 1.1 协议的一部分,用于处理服务器过早关闭的连接.

This is part of the HTTP 1.1 protocol to handle connections that are closed prematurely by servers.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.4.

我遇到过类似的情况,我们在几毫秒内发布了几次相同的表单.

I experienced a similar situation whereby we had the same form posted a couple of times within milliseconds apart.

通过wireshark 捕获的数据包确认了浏览器的重新传输,并且来自服务器的日志表明请求已到达.

A packet capture via wireshark confirmed the retransmission by the browser and logs from the server indicated the arrival of the requests.

另外进一步的调查还显示,负载均衡器(例如 F5)已经报告了重传行为的发生率.因此,也值得与您的负载平衡器供应商核实.

Also further investigation also revealed that the load balancer such as F5 have reported incidence of retransmission behavior. So it is worth checking with your load balancer vendor as well.

这篇关于为什么在服务器重置 TCP 后用户代理重新提交请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆