Why does the user agent resubmit a request after s

2019-02-17 04:49发布

问题:

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

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.

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.

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

回答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.

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

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.